akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))

using namespace std;
int a,b,c,d;
int k1,k2;
string s;

int main(){
  cin >> a;
  cout << a/3 << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

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

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

  if (N == 'A') {
    cout << 'T' << endl;
  } else if (N == 'T'){
    cout << 'A' << endl;
  } else if (N == 'C'){
    cout << 'G' << endl;
  } else if (N == 'G'){
    cout << 'C' << endl;
  }
  
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], fact;

void dfs_visit(int u){
	int v;
	color[u] = GRAY;
	fact++;
	d[u] = fact;
	for ( v = 0; v < n; v++ ){
		if ( M[u][v] == 0 ) continue;
		if ( color[v] == WHITE ){
		dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++fact;
}
	
void dfs(){
	int i, u;
	for ( i = 0; i < n; i++ ) color[i] = WHITE;
	fact = 0;
	
	for ( u = 0; u < n; u++ ) {
		if ( color[u] == WHITE ) dfs_visit(u);
	}
	for ( i = 0; i < n; i++ ){
		printf("%d %d %d\n", i+1, d[i], f[i]);
	}
}


int main(){
	int u, k, v; 
	int i, j;

	scanf("%d", &n);

	for ( i = 0; i <n; i++ ) {
		for ( j = 0; j <n; j++ ) M[i][j] = 0;
	}

	for ( i = 0; i < n; i++ ) {
		scanf("%d %d", &u, &k);
		u--;
		for ( j = 0; j < k; j++) {
    		scanf("%d", &v);
			v--;
			M[u][v] = 1;
		}
	}

  dfs();

  return 0;
}


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

#define pii pair<int, int>
#define endl "\n"
#define int long long
#define F first
#define S second
#define B begin
#define E end
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const ll P = 1e9 + 7;
const ll Q = 31;
 
using namespace std;
 
void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}

 
signed main()
{
    hello();

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


    vector <int> cnt(62);

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < 62; ++j)
            if (seq[i] & (1ll << j))
                ++cnt[j];
    }

    // show(cnt);

    int res = 0;
    for (int i = 0; i < 62; ++i)
    {
        res += cnt[i] * (n - cnt[i]) % P * ((1ll << i) % P) % P;
        res %= P;
    }

    cout << res << endl;
    
}

Measured memory_bytes: 2560
#include <cstdio>

using namespace std;

int N;
long long A[100005];

long long solve() {
    long long ret = 0;
    for (int i = 1; i <= N; i++) {
        long long p = A[i] / 2, q = A[i] % 2;
        if (q) {
            if (i+1 <= N && A[i+1]) p++, A[i+1]--;
        }
        ret += p;
    }
    return ret;
}

int main() {
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) scanf("%lld", A+i);
    long long ans = solve();
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;

signed main(){
    string s,t; cin>>s>>t;
    vector<char> r(26,'*'), rr(26,'*');
    rep(i,s.size()){
        if(r.at(s.at(i)-'a')=='*'){
            r.at(s.at(i)-'a')=t.at(i);
        }else{
            if(r.at(s.at(i)-'a')!=t.at(i)){
                cout<<"No"<<endl;
                return 0;
            }
        }
        if(rr.at(t.at(i)-'a')=='*'){
            rr.at(t.at(i)-'a')=s.at(i);
        }else{
            if(rr.at(t.at(i)-'a')!=s.at(i)){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
}

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

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);
	double max = 0.0;
	double min = Double.MAX_VALUE;

	while ( stdin.hasNextDouble() ) {
	    double height = stdin.nextDouble();

	    max = Math.max( height, max );
	    min = Math.min( height, min );
	}
	System.out.println( max - min );
	
    }
    
}

Measured memory_bytes: 18628
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(d)  (d).begin(),(d).end()
#define RALL(d) (d).rbegin(), (d).rend()
#define PB push_back
#define MP make_pair
#define SZ(d) int((d).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,d,b) for(int i=(d);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(d) memset((d), 0 ,sizeof(d))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main()
{
	string s;
	cin >> s;
	int n = s.size();
	int a = -1, b = -1;
	int m = 0;
	auto num = unordered_map<char, int>();
	FOR(i, 1, n) if(s[i] == s[i-1])
	{
		a = i;
		b = i + 1;
	}
	FOR(i, 2, n) if (s[i] == s[i - 2])
	{
		a = i - 1;
		b = i + 1;
	}
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 512
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    ret = 0
    for n in range(N):
        while A[n] % 2 == 0:
            A[n] //= 2
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11008
function main(input) {
    var a = input[0].split(" ")[0]-0;
    var b = input[0].split(" ")[1]-0;
    var c = input[0].split(" ")[2]-0;
    var k = input[1]-0;
    var arr = [a,b,c].sort((a,b)=>a-b);
    arr[2]*=Math.pow(2,k);
    
    console.log(arr[0]+arr[1]+arr[2]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int n, su=0, tmp;

	cin>> n;

	rep(i, n){
		cin>> tmp;
		su+=tmp;
	}

	cout<< su-n <<endl;
 
	return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
#define INF (0x3f3f3f3f)
using namespace std;
//solution1:
int answer[3][5] = { {2,5,63}, {2,5,20,63}, {2,5,20,30,63} };
int a[30005];
int n;
int main() {
  scanf("%d", &n);
  if(n<6) {
  for(int i=0;i<n;++i)
    printf("%d ",answer[n-3][i]);
  } else {
  int m = n%8, k=2;
  a[0]=2,a[1]=3,a[2]=4,a[3]=6;
  if( m==0||m==7 ) {
    a[4]=8,a[5]=9;
    a[6]=10,a[7]=12;
    for(int i=8;i<n;i=i+4,++k) {
      a[i] = 6*k+2;
      a[i+1] = 6*k+3;
      a[i+2] = 6*k+4;
      a[i+3] = 6*k+6;
    }
  } else {
    a[4] = (m==1||m==6) ? 9 : 8;
    a[5]=10,a[6]=12;
    for(int i=7;i<n;i=i+4,++k) {
      a[i] = 6*k+2;
      a[i+1] = 6*k+3;
      a[i+2] = 6*k+4;
      a[i+3] = 6*k+6;
    }
    if(m==2||m==5) {
      if(a[n-1]%6<=4) k--;
      a[n-1]=6*k+4;
    } else a[n-1]= 6*k;
  }
  for(int i=0;i<n;++i)
    printf("%d ",a[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var ni = Console.ReadLine().Split(' ');
            var n = int.Parse(ni[0]);
            var i = int.Parse(ni[1]);
            Console.WriteLine(n - i + 1);
        }
    }
}


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

int main(){
	double n, i;
	double x1, y1, x2, y2, x3, y3, x4, y4;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		if((y1-y2)*(x3-x4) == (y3-y4)*(x1-x2)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
function Main(inp) {
  var input = inp.split("\n");
  var n = Number(input[0]);
  var t = Number(input[1].split(' ')[0]);
  var a = Number(input[1].split(' ')[1]);
  var heights = input[2].split(' ').map(function(n) { return Number(n);});
  var diff = Number.MAX_VALUE;
  var index = -1;
  heights.forEach(function (h, i) {
      var d = Math.abs((t - h * 0.006) - a);
      if (d < diff) {
          diff = d;
          index = i; 
      }
  });
  console.log(index + 1);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21320
#include<iostream>
#include<vector>
using namespace std;
int main() 
{
	int N;

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

	vector<int> B(N);
	long long total = 0;
	B[0] = 0;
	for (int i = 1; i < N; i++) {
		if (A[i - 1] + B[i - 1] > A[i]) {
			B[i] = A[i - 1] + B[i - 1] - A[i];
			total += B[i];
		}
	}
	cout << total << endl;
}

Measured memory_bytes: 4772
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <cstdlib>
#include <queue>
#include <vector>
#include <map>
using namespace std;
int main() {
	string s,f,l;
	map<string,int> table;
	size_t n = 0;
	while( cin  >> s ) { 
		table[s] += 1;
		if ( table[s] > n ) {
			n = table[s];
			f = s;
		}
		if (s.size() > l.size() ) l = s;
	}
	cout << f << " " << l << endl;
}

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

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

	int q, com, x;
	string key;
	map<string, int> my_map;

	cin >> q;
	while (q--) {
		cin >> com >> key;
		if (com == 0) {
			cin >> x;
			my_map[key] = x;
		} else {
			cout << my_map[key] << endl;
		}
	}
}


Measured memory_bytes: 25972
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define add push_back
#define endl "\n"
const int INF = 0x3f3f3f3f;
const double pi = acos(-1);
using ll = long long;
using namespace std;

string s1, s2;
int cnt;
int main() {
    IOS
    cin >> s1 >> s2;
    for (int i = 0; i < 3; ++i) {
        cnt += (s1[i] == s2[i]);
    }
    cout << cnt << endl;
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void init_ios() {ios_base::sync_with_stdio(false); cin.tie(nullptr);}

long long x, y;

int main() {
	cin >> x >> y;

	if (x % y == 0) {
		cout << -1 << endl;
		return 0;
	}

	long long z = x * y / __gcd(x, y);
	cout << z + x << endl;


	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import numpy as np
 
N,W = map(int, input().split())
 
dp = [10 ** 10] * (N * (10 ** 3) + 1)
dp[0] = 0
dp = np.array(dp)
 
 
for i in range(N):
    w,v = map(int, input().split())
    dp[v:] = np.minimum(dp[v:] , dp[:-v] + w)
  
for i,count in enumerate(dp):
    if dp[i] <= W:
        ans = i
print(ans)

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

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

    string s[n];
    int t[n];

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

    string x;
    cin >> x;

    bool flag = false;
    int total = 0;

    for (int i = 0; i < n; i++) {
        if(flag == false) {
            if(x == s[i]) {
                flag = true;
            }
        }else {
            total += t[i];
        }

    }

    cout << total << endl;
}

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

int main(void){
  int N,i,j,k,count[30],len,tmp;
  char S[52][52];
  //char c;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%s",S[i]);
  }
  for(i=0;i<27;i++){
    count[i] = 100;
  }
  for(i=0;i<27;i++){
    for(j=0;j<N;j++){
      len = strlen(S[j]);
      tmp=0;
      for(k=0;k<len;k++){
        if(S[j][k] == i+97){
          //puts("OK");
          tmp++;
        }
      }
      //printf("%d\n",tmp);
      if(tmp < count[i]){
        //printf("%d\n",tmp);
        count[i]=tmp;
      }
    }
  }

  for(i=0;i<27;i++){
    for(j=0;j<count[i];j++){
      printf("%c",i+97);
    }
  }
  putchar('\n');
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(){
int a,b,c,d,e;
while(1){
scanf("%d %d",&a,&b);
if(a==0&&b==0)break;
for(d=0;d<a;d++){
	for(e=0;e<b;e++){
	printf("#");
	}
	printf("\n");
}
printf("\n");
}
return 0;
}


Measured memory_bytes: 2060
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b;
    cin >> a >> b;
    a=a==1?14:a;
    b=b==1?14:b;
    if(a>b) cout << "Alice" << endl;
    if(a<b) cout << "Bob" << endl;
    if(a==b) cout << "Draw" << endl;
}


Measured memory_bytes: 256
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Oct  9 22:12:40 2017

@author: kitagenbakurou
"""
import numpy as np
import copy

N = input()
N = int(N)
s = input().split()
s = [int(i) for i in s]

cnt = 1
for i in range(N) : 
    if s[i] % 2 == 0 : cnt *= 2
    else : cnt *= 1

print(3 ** N - cnt)


Measured memory_bytes: 21776
"""
https://atcoder.jp/contests/dp/tasks/dp_c
"""
import sys

N = int(sys.stdin.readline())
input_arr = []
for i in range(N):
    input_arr.append([int(i) for i in sys.stdin.readline().split(" ")])

def getMaxPoints():
    dp = []
    dp.append([
        max(input_arr[0][1], input_arr[0][2]),
        max(input_arr[0][0], input_arr[0][2]),
        max(input_arr[0][0], input_arr[0][1]),
    ])
    for i in range(1, N):
        dp.append(
            [
                input_arr[i][0] + max(dp[i-1][1], dp[i-1][2]),
                input_arr[i][1] + max(dp[i-1][0], dp[i-1][2]),
                input_arr[i][2] + max(dp[i-1][0], dp[i-1][1]),
            ]
        )
        
    return max(dp[-1])
sys.stdout.write(str(getMaxPoints()))

Measured memory_bytes: 48736
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

typedef pair<char, int> speP;

//N,E,S,W
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };

char mp[50][50];
void solve() {
	int h, w; cin >> h >> w;
	int x, y, d; d = 0;
	rep(i, h) {
		rep(j, w) {
			cin >> mp[i][j];
			if (mp[i][j] == 's') {
				x = i, y = j;
			}
		}
	}
	string s; cin >> s;
	int ans = 0;
	stack<int> st;
	int tmp = 0;
	rep(i, s.length()) {
		tmp++;
		if (s[i] == '['||s[i]=='{') {
			char memo = s[i];
			bool f; i++;
			char t;
			if (s[i] == '~')t = s[i + 1];
			else t = s[i];
			if (t == 'N') {
				if (d == 0)f = true;
				else f = false;
			}
			else if (t == 'E') {
				if (d == 1)f = true;
				else f = false;
			}
			else if (t == 'S') {
				if (d == 2)f = true;
				else f = false;
			}
			else if (t == 'W') {
				if (d == 3)f = true;
				else f = false;
			}
			else if (t == 'C') {
				int nx = x + dx[d], ny = y + dy[d];
				if (mp[nx][ny] == '#')f = true;
				else f = false;
			}
			else f = true;
			if (s[i] == '~')f = !f;
			
			if (f) {
				if (memo == '{') {
					st.push(i - 1);
				}
			}
			else {
				int c = 1;
				char b;
				if (memo == '[')b = ']';
				else b = '}';
				while (c) {
					if (s[i] == b)c--;
					else if (s[i] == memo)c++;
					i++;
				}
				i--;
			}
		}
		else if (s[i] == ']' || s[i] == '}') {
			if (s[i] == '}') {
				i = st.top(); st.pop();
				i--;
			}
		}
		else if(s[i]=='^'){
			ans++;
			int nx = x + dx[d], ny = y + dy[d];
			if (mp[nx][ny] != '#') {
				x = nx, y = ny;
			}
			if (mp[nx][ny] == 'g') {
				cout << ans << endl; return;
			}
		}
		else if (s[i] == 'v') {
			ans++;
			int nx = x - dx[d], ny = y - dy[d];
			if (mp[nx][ny] != '#') {
				x = nx, y = ny;
			}
			if (mp[nx][ny] == 'g') {
				cout << ans << endl; return;
			}
		}
		else if (s[i] == '<') {
			ans++;
			d--; if (d < 0)d += 4;
		}
		else if (s[i] == '>') {
			ans++; d++;
			if (d == 4)d = 0;
		}
		if (tmp >2000000) {
			cout << -1 << endl; return;
		}
	}
	cout << -1 << endl; return;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> pos(n);
  for (int i = 0; i < n; i++) {
    cin >> pos[i].first >> pos[i].second;
  }
  vector<pair<int, int>> checkP(m);
  for (int i = 0; i < m; i++) {
    cin >> checkP[i].first >> checkP[i].second;
  }
  for (int i = 0; i < n; i++) {
    int dist = abs(pos[i].first - checkP[m - 1].first) +
               abs(pos[i].second - checkP[m - 1].second);
    int x = m - 1;
    for (int j = m - 1; 0 <= j; j--) {
      int nowDist = abs(pos[i].first - checkP[j].first) +
                    abs(pos[i].second - checkP[j].second);
      if (dist >= nowDist) {
        dist = nowDist;
        x = j;
      }
    }
    cout << x + 1 << endl;
  }
  return 0;
}

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

set<ll> f(ll x) {
  set<ll> s;
  for (ll i = 2; i * i <= x; ++i) {
    if (x % i == 0) s.insert(i);
    while (x % i == 0) x /= i;
  }
  if (x > 1) s.insert(x);
  return s;
}

bool isPrime(ll x) {
  for (ll i = 2; i * i <= x; ++i)
    if (x % i == 0) return false;
  return true;
}

int main() {
  ll a, b;
  cin >> a >> b;
  auto as = f(a);
  auto bs = f(b);
  set<ll> x;
  set_intersection(as.begin(), as.end(), bs.begin(), bs.end(),
                   inserter(x, x.end()));
  ll t = 1;
  for (ll a : x)
    if (isPrime(a)) ++t;
  cout << t << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <sstream>
#include<ctime>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define mii map<int,int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rep(i,l,r) for(int i=l;i<r;i++) 
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mod 998244353 
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define INF 0x3f3f3f3f
ll MOD(ll a, ll b)
{
    if(a>b)
    return a-b;
    else
    return b-a;
}
ll power(ll x,ll y, ll p)
{
    ll res = 1;      
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%p;
        y = y>>1; 
        x = (x*x)%p;  
    }
    return res;
}
ll logg(ll a)
{
    ll x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
 
}
int main()
{
    fastio;
    int n;
    cin>>n;
    vi A(n);
    int sum=0;
    rep(i,0,n)
    {
        cin>>A[i];
        sum+=A[i];
    }
    int p=0;
    rep(i,0,n)
    {
        sum-=A[i];
        p+=A[i]*sum;
    }
    cout<<p;
}

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

typedef long long ll;
const ll MOD = (ll)1e9 + 7;
ll add(ll x, ll y)
{
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y)
{
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y)
{
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p)
{
	if (p == 0) return 1;
	if ((p & 1) || p == 2) return mult(x, bin_pow(x, p - 1));
	return bin_pow(bin_pow(x, 2), p / 2);
}
ll rev(ll x)
{
	return bin_pow(x, MOD - 2);
}

const int N = 100100;
int n;
int g[N];
int deg[N];
int dist[N];
int q[N];
int topQ;
ll f[N], rf[N];
int cntLen[N];

ll getC(int n, int k)
{
	if (k < 0 || k > n) return 0;
	return mult(f[n], mult(rf[k], rf[n - k]));
}

void precalc()
{
	f[0] = 1;
	for (int i = 1; i < N; i++)
		f[i] = mult(f[i - 1], i);
	rf[N - 1] = rev(f[N - 1]);
	for (int i = N - 1; i > 0; i--)
		rf[i - 1] = mult(rf[i], i);
	return;
}

ll solveEven(ll x, ll l)
{
	ll ans = 0;
	ll res = 1;
	for (int i = 0; i <= x / 2; i++)
	{
		ans = add(ans, mult(res, getC(x, 2 * i)));
		res = mult(res, l * (2 * i + 1));
	}
	return ans;
}

ll solveOdd(ll x, ll l)
{
	ll ans = 0;
	ll res = 1;
	for (int i = 0; i <= x / 2; i++)
	{
		ans = add(ans, mult(bin_pow(2, x - 2 * i), mult(res, getC(x, 2 * i))));
		res = mult(res, l * (2 * i + 1));
	}
	return ans;
}

ll solveCycle(vector<int> a)
{
	bool noZero = true, allOne = true;
	for (int x : a)
	{
		if (x == 0) noZero = false;
		if (x != 1) allOne = false;
	}
	if (noZero) return (ll)allOne;
	reverse(a.begin(), a.end());
	int p = 0;
	while(a[p]) p++;
	int len = a.size();
	while(p < len && a[p] == 0) p++;
	if (p != len)
		rotate(a.begin(), a.begin() + p, a.end());
	if (a.back()) throw;
	ll ans = 1;
	for (int i = 0; i < len; i++)
	{
		if (a[i] == 0) continue;
		if (i + a[i] > len) return 0;
		bool ok = true;
		for (int j = 1; j < a[i]; j++)
			ok &= (a[i + j] == 0);
		if (!ok) return 0;
		if (i + a[i] < len && a[i + a[i]] == 0)
			ans = mult(ans, 2);
	}
	return ans;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	precalc();
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &g[i]);
		g[i]--;
		deg[g[i]]++;
	}
	for (int i = 0; i < n; i++)
		if (deg[i] > 2)
		{
			printf("0\n");
			return 0;
		}
	for (int i = 0; i < n; i++)
		if (deg[i] == 0)
			q[topQ++] = i;
	for (int i = 0; i < topQ; i++)
	{
		int v = q[i];
		int u = g[v];
		deg[u]--;
		if (dist[u] > 0)
		{
			printf("0\n");
			return 0;
		}
		dist[u] = dist[v] + 1;
		if (deg[u] == 0)
			q[topQ++] = u;
	}
	ll ans = 1;
	for (int v = 0; v < n; v++)
	{
		if (deg[v] == 0) continue;
		vector<int> a;
		while(deg[v] != 0)
		{
			a.push_back(dist[v]);
			deg[v] = 0;
			v = g[v];
		}
		bool allZero = true;
		for (int x : a)
		{
			if (x != 0) allZero = false;
		}
		if (allZero)
		{
			cntLen[(int)a.size()]++;
			continue;
		}
		ans = mult(ans, solveCycle(a));
	}
	for (int x = 1; x <= n; x++)
	{
		if (cntLen[x] == 0) continue;
		ans = mult(ans, (x % 2 == 0 || x == 1 ? solveEven(cntLen[x], x) : solveOdd(cntLen[x], x)));
	}
	printf("%lld\n", ans);

	return 0;
}

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

const int maxn = 1e5+10;
typedef long long ll;
int fa[maxn];
int fnd(int x){
    return (fa[x]<0)?x:(fa[x]=fnd(fa[x]));
}
bool uni(int a,int b){
    a=fnd(a),b=fnd(b);
    if(a==b)    return false;
    if(fa[a]>fa[b]) swap(a,b);
    fa[a]+=fa[b];
    fa[b]=a;
    return true;
}
#define yes {cout<<"Yes"<<endl;return 0;}
#define no {cout<<"No"<<endl;return 0;}
int c[maxn],u[maxn],v[maxn];
int main(){
    ios::sync_with_stdio(false);
    memset(fa,-1,sizeof fa);
    int N,Q;    ll M;
    cin>>N>>M>>Q;
    for(int i=0;i<Q;++i)
        cin>>u[i]>>v[i]>>c[i];
    for(int i=0;i<Q;++i)
        if(c[i]==0)
            uni(u[i],v[i]);
    for(int i=0;i<Q;++i)
    {
        if(c[i]==1)
            if(fnd(u[i])==fnd(v[i]))
                no
    }
    int cnt=0;
    for(int i=0;i<Q;++i)
        if(c[i]==1)
            cnt++;
    ll cu=0;
    ll MAX=0,MIN=0;
    for(int i=0;i<N;++i)
        if(fa[i]<0)
            cu++;
    if(cnt==0)
        MIN=N-1;
    else MIN=N;
    MAX = N-cu+cu*(cu-1)/2;
    //cout<<MIN<<" "<<MAX<<endl;

    if(cu==1)
        if(M==N-1)  yes
        else no
    if(cu==2)
        if(cnt==0&&M==N-1)  yes
        else no

    if(M<=MAX&&M>=MIN)  yes
    no
}


Measured memory_bytes: 1792
N = int(input())
W = [input() for i in range(N)]

l = []

for i in range(N):
  if i != 0:
    if W[i-1][-1] != W[i][0]:
      print('No')
      break
  
  if W[i] in l:
    print('No')
    break
    
  l.append(W[i])
else:
  print('Yes')

Measured memory_bytes: 9188
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int n = scanner.nextInt();
            int x = scanner.nextInt();
            if (n == 0 && x == 0) break;
            int count = 0;
            for (int i = 1; i <= n-2; i++) {
                for (int j = i+1; j <= n-1; j++) {
                    for (int k = j+1; k <= n; k++) {
                        if (i + j + k == x) count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
}


Measured memory_bytes: 26456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	vector<ll> p(n);
	rep(i,n){
		cin>>p[i];
	}
	sort(begin(p),end(p));
	ll ans=0;
	rep(i,k) ans+=p[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 3660
object Main {
  def main(args: Array[String]) = {
    val input: String = readLine()
    val list: Array[String] = input.split(" ")
    val a: Int = list(0).toInt
    val b: Int = list(1).toInt
    
    val area: Int = a * b
    val perimeter: Int = (a + b) * 2
    println(area + " " + perimeter)
  }  
  //def readLine(): String = {"3 5"}
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;

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

	int cnt = 0;
	if(s <= 2){
		cout << 4 << endl;
		return 0;
	}else{
		while(s != 4){
			if(s % 2 == 0){
				s /= 2;
			}else{
				s = s * 3 + 1;
			}

			cnt ++;
		}
	}

	cout << cnt+4 << endl;

    return 0;
}



Measured memory_bytes: 256
<?php
$n = trim(fgets(STDIN));
$arr = explode(" ",trim(fgets(STDIN)));
asort($arr);
$arr = array_values($arr);

if($n == 2){
    echo ($arr[0] + $arr[1]) / 2;
}else{
    $a = ($arr[0] + $arr[1]) / 2;
    for($i=2; $i<$n; $i++){
        $a = ($a + $arr[$i]) / 2;
    }
    echo $a;
}
?>

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

#define INF 0x7fffffff

int main() {
	int		i,j,k,n,m,x,y,ans = 0;
	int		tmp = INF;
	string	str;
	
	char a[100] = {0};
	char b[100] = {0};
	char c[100] = {0};
	char d[100] = {0};
	char e[100] = {0};
	char f[100] = {0};

	
	cin >> str;
	
	n = str.size();

	for(i=0;i<(n-1)/2;i++) {
		a[i] = str[i];
	}
	
	for(i=(n-1)/2-1,j=0;i>=0;i--,j++) {
		b[j] = str[i];
	}

	for(i=(n+3)/2-1,j=0;i<n;i++,j++) {
		c[j] = str[i];
	}
	
	for(i=n-1,j=0;i>=(n+3)/2-1;i--,j++) {
		d[j] = str[i];
	}

	for(i=0,j=n-1;i<n;i++,j--) {
		e[i] = str[i];
		f[j] = str[i];
	}
	
	if ((strcmp(a,b)==0)&&(strcmp(c,d)==0)&&(strcmp(e,f)==0)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	

	/*
	cout << a << endl;
	cout << b << endl;
	cout << c << endl;
	cout << d << endl;

	cout << str << endl;
	*/
}


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

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

  ll ans = -1000000000000000000;
  ans = max(a * c, ans);
  ans = max(a * d, ans);
  ans = max(b * c, ans);
  ans = max(b * d, ans);

  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

void printvec(vi& x, int size = 0) {
    cout << x.front();
    for (int i = 1; i < (size == 0 ? x.size() : size); i++) {
        cout << " " << x[i];
    }
    cout << endl;
}

int main() {
    i64 n;
    cin >> n;
    int ok = 0, k;
    for (i64 i = 1; i <= n; i++) {
        if (i * (i + 1) / 2 == n) {
            ok = 1;
            k = i + 1;
        }
    }
    if (!ok) {
        cout << "No" << endl;
        return 0;
    }

    vvi ans(k);
    int crt = 1;
    int hoge = 1;
    for (int i = 0; i < k; i++) {
        for (int j = i + 1; j < k; j++) {
            ans[i].push_back(hoge);
            ans[j].push_back(hoge++);
        }
    }

    cout << "Yes" << endl;
    cout << k << endl;
    for (int i = 0; i < k; i++) {
        cout << ans[i].size() << " ";
        printvec(ans[i]);
    }
}

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

#define MAX 200002

int n;
int v;

vector<int> vv;

int dp[MAX][20];
int val[MAX];



map<int, vector<int> > mp;

vector<vector<int> > V;


vector<int> VV;

int mx = 0;

int D[1 << 18];
bool ok(){
	if (VV.size() == 0){
		return true;
	}
	int N = VV.size();
	for (int i = 1; i <= mx; i++){
		dp[N - 1][i] = N - 1;
	}
	for (int i = N - 2; i >= 0; i--){
		long long int d = VV[i + 1] - VV[i];
		for (int j = 1; j <= mx; j++){
			if (d <= val[j]){
				dp[i][j] = dp[i + 1][j];
			}
			else{
				dp[i][j] = i;
			}
		}
	}
	memset(D, 0, sizeof(D));
	for (int i = 0; i < (1 << mx); i++){
		if (D[i] >= N){
			return true;
		}
		for (int j = 1; j <= mx; j++){
			if ((i >> (j - 1)) & 1)continue;
			int go = i | (1 << (j - 1));
			D[go] = max(D[go], dp[D[i]][j]+1);
		}
	}
	return false;
}
bool ans[MAX];

int main(){
	cin >> n >> v;
	for (int i = 0; i < n; i++){
		int x;
		scanf("%d", &x);
		vv.push_back(x);
	}
	
	val[0] = v;
	for (mx = 1; v / 2 >= 0; mx++){
		v /= 2;
		val[mx] = v;
		if (v == 0)break;
	}
	for (int i = 0; i <= mx; i++){
		dp[n - 1][i] = n-1;
	}
	for (int i = n - 2; i >= 0; i--){
		long long int d = vv[i + 1] - vv[i];
		for (int j = 0; j <= mx; j++){
			if (d <= val[j]){
				dp[i][j] = dp[i + 1][j];
			}
			else{
				dp[i][j] = i;
			}
		}
	}
	for (int i = 0; i < n; i++){
		mp[dp[i][0]].push_back(i);
	}
	if (mp.size()>mx+1){
		
	}
	else{
		for (auto it = mp.begin(); it != mp.end(); it++){
			VV.clear();
			for (int i = 0; i < n; i++){
				if (i < (*it).second[0] || (*it).second.back() < i){
					VV.push_back(vv[i]);
				}
			}
			if (ok()){
				vector<int> &vvv = (*it).second;
				for (int j = 0; j < vvv.size(); j++){
					ans[vvv[j]] = true;
				}
			}
		}
	}
	for (int i = 0; i < n; i++){
		if (ans[i] == true){
			puts("Possible");
		}
		else{
			puts("Impossible");
		}
	}
	return 0;
}

Measured memory_bytes: 21636
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
  int x,flag(0),ans;

  cin >> x;

  for(int i = 0 ;i < 50000;i++){
      if(int(i *1.08) == x){
          ans = i;
          flag++;
      }
  }
  if(flag >= 1){
      cout << ans;
  }else{
      cout << ":(";
  }
  
}
   


Measured memory_bytes: 256
#include <cstdio>

int main()
{
  int n, q;
  char s[100001];
  int acc[100001];
  acc[0] = 0;
  scanf("%d%d%s", &n, &q, s);
  for (int i = 0; i < n; ++i)
  {
    acc[i + 1] = acc[i] + (s[i] == 'A' && s[i + 1] == 'C');
  }
  for (int i = 0; i < q; ++i)
  {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", acc[r - 1] - acc[l - 1]);
  }
  return 0;
}

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

#define nil NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *p;
  int key;
};
typedef struct node * Node;

Node root;

Node treeMinimum(Node);
Node treeMaximum(Node);
Node treeSearch(Node, int);
Node treeSuccessor(Node);
void treeDelete(Node);
void transplant(Node,Node);
void insert(int);
void inorder(Node);
void preorder(Node);

int main(){
  int n, a, x;
  char command[20];
  scanf("%d",&n);

  for(a = 0; a < n; a++){
    scanf("%s",command);
    if(command[0] == 'f'){
      scanf("%d",&x);
      Node t = treeSearch(root,x);
      if(t != nil) printf("yes\n");
      else printf("no\n");
    }
    else if(command[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(command[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(command[0] == 'd'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }

  return 0;
}

Node treeMinimum(Node x){
  while(x->left != nil) x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != nil) x = x->right;
  return x;
}

Node treeSearch(Node x, int k){
  if(x == nil || k == x->key) return x;
  if(k < x->key) return treeSearch(x->left,k);
  else return treeSearch(x->right,k);
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != nil) return treeMinimum(x->right);
  y = x->p;
  while(y != nil && x == y->right){
    x = y;
    y = y->p;
  }
  return y;
}

void treeDelete(Node z){
  Node y;
  if(z->left == nil) transplant(z,z->right);
  else if(z->right == nil) transplant(z,z->left);
  else{
    y = treeMinimum(z->right);
    if(y->p != z){
      transplant(y,y->right);
      y->right = z->right;
      y->right->p = y;
    }
    transplant(z,y);
    y->left = z->left;
    y->left->p = y;
  }
}

void transplant(Node u, Node v){
  if(u->p == nil) root = v;
  else if(u == u->p->left) u->p->left = v;
  else u->p->right = v;
  if(v != nil) v->p = u->p;
}

void insert(int k){
  Node y = nil;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = nil;
  z->right = nil;
  
  while(x != nil){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->p = y;
  if(y == nil) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node x){
  if(x != nil){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }
}

void preorder(Node x){
  if(x != nil){
    printf(" %d",x->key);
    preorder(x->left);
    preorder(x->right);
  }
}



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

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define int ll
const int INF = 1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
typedef pair<int, int> Vec2;
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


int h, w;
int d[1000][1000];
vector<string> grid(1000);

void printd() {
	cout << endl;
	rep(i, h) {
		rep(j, w) {
			cout << d[j][i];
		}
		cout << endl;
	}
	cout << endl;
}

void bfs() {
	queue<Vec2> Q;
	rep(i, h) {
		rep(j, w) {
			if (grid[i][j] == '#') {
				Q.push({ j,i });
				d[j][i] = 0;
			}
		}
	}
	while (!Q.empty()) {
		int x = Q.front().first;
		int y = Q.front().second;
		Q.pop();
		rep(i, 4) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (nx >= 0 and nx < w and ny >= 0 and ny < h) {
				if(d[nx][ny] == INF) {
					Q.push({ nx,ny });
					d[nx][ny] = d[x][y] + 1;
				}
			}
		}
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin >> h >> w;
	vector<Vec2> vec;
	rep(i, h) {
		cin >> grid[i];
	}
	rep(i, w) {
		rep(j, h)
			d[i][j] = INF;
	}
	bfs();
	int ans = 0;
	rep(i, h) {
		rep(j, w) {
			ans = max(ans, d[j][i]);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 25524
#include <iostream>
#include <unordered_set>

int main()
{
	std::unordered_set<int> firstIsland;
	int n, m, a[200010], b[200010];
	std::cin >> n >> m;
	
	for (int i = 0; i < m; ++i)
	{
		std::cin >> a[i] >> b[i];
		if (a[i] == 1)
			firstIsland.insert(b[i]);
		else if (b[i] == 1)
			firstIsland.insert(a[i]);
	}
	
	for (int i = 0; i < m; ++i)
	{
		if (a[i] == n)
		{
			if (firstIsland.find(b[i]) != firstIsland.end())
			{
				std::cout << "POSSIBLE";
				return 0;
			}
		}
		
		if (b[i] == n)
		{
			if (firstIsland.find(a[i]) != firstIsland.end())
			{
				std::cout << "POSSIBLE";
				return 0;
			}
		}
	}
	
	std::cout << "IMPOSSIBLE";
	return 0;
}

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

int main(void){
    string cards, res;
    int n, h;
    
    while(1){
        cin >> cards;
        if(cards == "-") break;
        cin >> n;

        for(int i = 0; i < n; i++){
            cin >> h;
            res = cards.substr(0, h);
            cards.erase(0, h);
            cards += res;
        }
        cout << cards << endl;
    }
    return 0;
}


Measured memory_bytes: 3148
#include<iostream>
using namespace std;
 
int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(a-c)<=d){
        cout<<"Yes"<<endl;
    }else if(abs(a-b)<=d && abs(b-c)<=d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define INF 10000000
int a;
int A[2000000];

int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

void maxHeapify(int i){
  int l = left(i);
  int r = right(i);
  int large;
  int num;

  if(l <= a && A[l] > A[i]){
    large = l;
  }else{
    large = i;
  }
  if(r <= a && A[r] > A[large]){
    large = r;
  }

  if(large != i){
    num = A[i];
    A[i] = A[large];
    A[large] = num;
    maxHeapify(large);
  }
}


int exact(){
  int max;
  if(a<1)return -INF;

  max = A[1];
  A[1] = A[a--];
  maxHeapify(1);

  return max;
}


void heapIncreaseKey(int A[],int i,int k){
  int num;
  if(k < A[i])return;

  A[i] = k;

  while(i > 1 && A[i/2] < A[i]){
    num = A[i];
    A[i] = A[i/2];
    A[i/2] = num;
    i = i/2;
  }
}

void insert(int k){
  a++;
  A[a] = -INF;
  heapIncreaseKey(A,a,k);
}

int main(){
  int k;
  char c[10];
  a = 0;
  while(1){
    scanf("%s",c);

    if(c[0] == 'e' && c[1] == 'n')break;
    else if(c[0] == 'i'){
      scanf("%d",&k);
      insert(k);
    }else{
      printf("%d\n",exact());
    }
  }

  return 0;
}



Measured memory_bytes: 5644
N, M = map(int, input().split())
D = [0 for _ in range(N)]
ansAC =0 
ansWA = 0

for i in range(M):
  p, S = input().split()
  p = int(p)-1
  if S=="WA":
    if D[p] != -1:
      D[p] += 1
  else:
    if D[p] != -1:
      ansAC += 1
      ansWA += D[p]
      D[p]= -1

print (ansAC,ansWA)

Measured memory_bytes: 3888
#include <iostream>
#include <unordered_map>
using namespace std;
int n, ans;
unordered_map<int, int> h;
int main() 
{
	int i, x, y;
	cin >> n;
	for (i=0; i<n; ++i)
	{
		cin >> x;
		++h[x];
	}
	for (auto j=h.begin(); j!=h.end(); ++j)
	{
		x=j->first;
		y=j->second;
		if (y<x) ans+=y;
		if (y>x) ans+=y-x;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4260
#include <iostream>

using namespace std;

int main()
{
  int cards[6][16] = {{}};
  int n,d,i,B;
  char A;
  cin >>  n;
  // scanf("%d\n",&n);
  for(i=1;i<=n;i++){
    cin  >>  A >>  d ; 
    // scanf("%c %d\n",&A,&d);

    if(A=='S') {cards[0][d]=1;} 
    if(A=='H') {cards[1][d]=1;}  
    if(A=='C') {cards[2][d]=1;}  
    if(A=='D') {cards[3][d]=1;}  
  }

  for(d=1;d<=13;d++){
    if(cards[0][d]!=1) {//printf("\nS %d\n",d);}
      cout << "S" <<  ' ' << d << '\n';  
    }
  }
  
  for(d=1;d<=13;d++){
    if(cards[1][d]!=1) {//printf("H %d\n",d);}
      cout << "H" << ' ' << d << '\n';  
    }
  }
   
  for(d=1;d<=13;d++){  
    if(cards[2][d]!=1) {//printf("C %d\n",d);}
      cout << "C" << ' ' << d << '\n';
    }
  }
   
  for(d=1;d<=13;d++){  
    if(cards[3][d]!=1) {//printf("D %d\n",d);}
      cout << "D" << ' ' << d << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


i64 n, a, b, v[101];

i64 beki(int x, int y){
	i64 cnt = 1;
	for(int i = 0; i < y; i++){
		cnt *= x;
	}
	return cnt;
}

i64 nCm(int x, int y){
	i64 cnt = 1;
	bool used[30] = {0};
	y = min(y, x-y);
	for(int i = 0; i < y; i++){
		cnt *= x--;
		for(int i = 2; i <= y; i++){
			if(!used[i] && cnt % i == 0){
				cnt /= i;
				used[i] = 1;
			}
		}
	}
	return cnt;
}

int main(){
	cin >> n >> a >> b;
	for(int i = 0; i < n; i++){cin >> v[i];}
	sort(v, v+n);
	
	double ans = 0;
	for(int i = 0; i < a; i++){
		ans += v[n-i-1];
	}
	ans /= a;
	printf("%.10f\n", ans);
	
	int cnt = 0;
	bool all = (v[n-1] == v[n-a]);
	for(int i = 0; i < n; i++){
		if(v[i] == v[n-a]) cnt++;
	}
	
	if(all){
		i64 c = 0;
		for(int i = a; i <= b; i++){
			if(cnt < i) break;
			c += nCm(cnt, i);
		}
		cout << c << endl;
	}
	else{
		int c = a;
		for(int i = n-1; i >= 0; i--){
			if(v[n-a] == v[i])
				break;
			c--;
		}
		cout << nCm(cnt, c) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
x,y = map(int,input().split())
a =[1,3,5,7,8,10,12]
b = [4,6,9,11]
c =[2]

def grouping(x,y):
  if x in a and y in a:
    print('Yes')
  elif x in b and y in b:
    print('Yes')
  elif x in c and y in c:
    print('Yes')
  else:
    print('No')


grouping(x,y)



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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

void Main(){
	int n, m, c;
	cin >> n >> m >> c;
	vi b(m);
	rep(i,m) cin >> b[i];

	auto f = [&](vi a){
		int temp = c;
		rep(i,m) temp += b[i]*a[i];
		return (temp > 0);
	};

	int cnt = 0;
	rep(i,n){
		vi a(m);
		rep(j,m) cin >> a[j]; 
		if(f(a)) cnt++;
	}

	cout << cnt << endl;
	return;
}

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

Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false)
#define int long long
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define INF 1e18

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

const int maxn = 2e5 + 10;
string str;
int a[maxn],b[maxn],cnt[2020];
int fac[maxn];
signed main() {
  IO;
  cin >> str;
  reverse(str.begin(),str.end());
  fac[0] = 1;
  for(int i = 1; i < maxn; i++) fac[i] = fac[i-1] * 10 % 2019;
  for(int i = 0 ; i < str.size() ; i++){
    a[i] = (str[i] - '0') * fac[i] % 2019;
  }
  b[0] = a[0];
  for(int i = 1 ; i < str.size() ; i++){
    b[i] = (b[i-1] + a[i]) % 2019;
  }
//  for(int i = 0 ; i < str.size() ; i++) cout << b[i] << ' ';
//  cout << '\n';
  mset(cnt,0);
  int ans = 0;
  cnt[0]++;
  for(int i = 0; i < str.size() ; i++){
    ans += cnt[b[i]];
    cnt[b[i]]++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 8356