akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

    private void solve(FastScanner sc) {
        int n = sc.nextInt();
        long tx = 1, ax = 1;
        for (int i = 0; i < n; i++) {
            int t = sc.nextInt();
            int a = sc.nextInt();
            long y = Math.max(-Math.floorDiv(-tx,t), -Math.floorDiv(-ax,a));
            tx = t*y;
            ax = a*y;
        }
        System.out.println(tx+ax);
    }

    /*
     * template
     */

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        new Main().solve(sc);
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int bufLen = 0;

        private boolean hasNextByte() {
            if (ptr < bufLen) {
                return true;
            } else {
                ptr = 0;
                try {
                    bufLen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (bufLen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
            return hasNextByte();
        }

        String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }

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

Measured memory_bytes: 8276
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b;
lol i[500000];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol c=0,d=0,e=0,f=0,g=0,h=0;
  cin >>a>>b;
  bool ans=false;
  for(int n=0;n<a;n++){
      cin >>i[n];
      d=c,c=i[n];
      if(d+c>=b) ans=true,g=n;
  }
  if(!ans){
      cout <<"Impossible\n";
      return 0;
  }
  cout <<"Possible\n";
  for(int n=1;n<g;n++) cout <<n<<'\n';
  for(int n=a-1;n>g;n--) cout <<n<<'\n';
  cout <<g<<'\n';
  return (0);
}


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        int c = 0;
        for(int i = 100; i>0; i--) {
            if(a % i == 0 && b % i == 0) {
                c++;
                if(c == k) {
                    System.out.println(i);
                }
            }
        }

    }


}


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

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  // ### 入力例
  // A 1円
  // B 1000円
  // C 500円
  //
  // C*2 = 1000円
  // A+B = 1001円
  int ans = 0;
  // A,Bを1枚ずつ買うより、ABを買う方が安い場合
  if ((c*2) < (a+b)) {
    // A,Bの少ない方のノルマを満たす枚数だけAB買う
    // これでA,Bのいずれかのノルマ or 同数の場合は両方のノルマが満たされる
    int ab_num = min(x, y) * 2;
    ans += c * ab_num;

    // 残りのノルマ
    x = x - (ab_num / 2);
    y = y - (ab_num / 2);

    // Aのノルマを満たした場合、Bを買い足す
    if (x == 0) {
      // Bを1枚買う方が安いか、ABを2枚買う方が安いか
      if (b < (c*2)) {
        ans += b * y;
      } else {
        ans += c * (y*2);
      }
    // Bのノルマを満たした場合、Aを買い足す
    } else {
      if (a < (c*2)) {
        ans += a * x;
      } else {
        ans += c * (x*2);
      }
    }
  // ABを買うより、A,Bを1枚ずつ買う方が安い場合
  } else {
    ans += a * x;
    ans += b * y;
  }

  cout << ans << endl;
  return 0;
}


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

using i64 = int64_t;

int main(){
    char b;
    cin >> b;
    char ans;
    if(b == 'A')ans = 'T';
    else if(b == 'T')ans = 'A';
    else if(b == 'C')ans = 'G';
    else ans = 'C';
    cout << ans << endl;

    return 0;
}


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

int main() {
  int N, Q;
  cin >> N;
  vector<int> A(N);
  vector<int> D(100000);
  long long sum = 0;
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
    sum += A.at(i);
  }
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  for(int i = 0; i < Q; i++) {
    cin >> B.at(i) >> C.at(i);
  }
  for(int i = 0; i < N; i++) {
    D.at(A.at(i)-1)++;
  }
  for(int i = 0; i < Q; i++) {
    if(D.at(B.at(i)-1) != 0) {
      int p = D.at(B.at(i)-1);
      D.at(C.at(i)-1) += D.at(B.at(i)-1);
      D.at(B.at(i)-1) = 0;
      cout << sum + (C.at(i)-B.at(i)) * p << endl;
      sum += (C.at(i)-B.at(i)) * p;
    }
    else {
      cout << sum << endl;
    }
  }
}


Measured memory_bytes: 4776
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
using namespace std;
int main()
{
 	ll i,j;
	double n,k,p1=0.0,p2=0.0,p3=0.0,p=0.0;
 	cin>>n>>k;
 	if(n>=k)
 	{
 	  p1+=(n-k+1.0)/n;
	  rep(i,1,k)
	  {
	  	ll s1=0;
	  	s1+=i;
	  	ll ct1=0;
	  	while(s1<k)
	  	 {
	  	   s1=2*s1;
			 ct1++;	
		  }
		  p2+=(1.0/n)*pow(0.5,ct1);
	  } 	
	 }
	 else
	 {
	 	rep(j,1,n+1)
	 	{
	 		ll s2=0;
	 		s2+=j;
	 		ll ct2=0;
	 		while(s2<k)
	 		{
	 			s2=2*s2;
	 			ct2++;
			 }
			 //cout<<ct2<<endl;
			 p3+=(1.0/n)*pow(0.5,ct2);
			 //cout<<p3<<endl;
		 }
	 }
	 p+=p1+p2+p3;
	 printf("%.10f\n",p);
	
	
	
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstring>

using namespace std;

int g[10][10][10];
// x,y,z,xy2,xz2,yz2,xyz4
int dx[14] = {1,0,0,1, 1,1, 1,0, 0,1, 1,-1,-1};
int dy[14] = {0,1,0,1,-1,0, 0,1, 1,1,-1, 1,-1};
int dz[14] = {0,0,1,0, 0,1,-1,1,-1,1, 1, 1, 1};
string str[2] = {"Black", "White"};

int a, b, c, x, y, z, t;

int check() {
    int k = 0;
    for (int i = 0; i < 13; i++) {
        int x2 = x, y2 = y, z2 = z;
        int cnt = 1;
        while (1) {
            if (g[x2-dx[i]][y2-dy[i]][z2-dz[i]] == t) {
                x2 -= dx[i];
                y2 -= dy[i];
                z2 -= dz[i];
            } 
            else break;
        }
        while (1) {
            if (g[x2+dx[i]][y2+dy[i]][z2+dz[i]] == t) {
                x2 += dx[i];
                y2 += dy[i];
                z2 += dz[i];
                cnt++;
            }
            else break;
        }
        k = max(k, cnt);
        //if (cnt >= b) cout << k << " ";
        if (cnt >= b) return 1;
    }
    //cout << k << " ";
    return 0;
}

int main(void){
    while (cin >> a >> b >> c && a) {
        bool f = false;
        int ans = 0;
        memset(g, 0, sizeof(g));
        for (int i = 0; i < c; i++) {
            cin >> x >> y;
            if (f) continue;
            
            t = i%2 + 1;
            for (z = 1; z < a+1; z++) {
                if (g[x][y][z] == 0) {
                    g[x][y][z] = t;
                    break;
                } 
            }
            f = check();
            if (f) ans = i+1;
        }
        if (f) cout << str[(ans-1)%2] << " " << ans << endl;
        else cout << "Draw" << endl;
    }
}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void pout(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void pout(const T &value, const Args&... args){std::cout << value << " ";pout(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  i64 a, b, c, k;
  while(cin >> a >> b >> c >> k){
    i64 ans = 0;

    ans += min<i64>(a, k);
    k = max<i64>(0LL, k-a);

    k = max<i64>(0LL, k-b);

    ans -= min<i64>(c, k);
    
    pout(ans);
  }

  return 0;
}


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

int main() {
    ll x, y;
    cin >> x >> y;
    
    ll ans = 1;
    while (y >= x * 2) 
    {
        ans++;
        x *= 2;
        // cout << "x: " << x << endl;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    int t = (int)sqrt(n);
    cout <<t*t<<endl;
}

Measured memory_bytes: 256
//#include<studio.h>
#include<iostream>
using namespace std;
int main()
{
	int a, b, c;
	cin >>a >> b >> c;
	if (a < b&&b < c) { std::cout << "Yes"<<endl; }
	else { std::cout << "No" << endl; }
	return 0;
}

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

int main() {
  int A, B; cin >> A >> B;
  A--; B--;
  vector<vector<int>> G(100, vector<int>(100));
  for (int i = 0; i < 50; i++) {
    for (int j = 0; j < 100; j++) G.at(i).at(j) = 1;
  }
  int wy = 1, wx = 1;
  while (A > 0) {
    G.at(wy).at(wx) = 0;
    A--;
    if (wx == 99) {
      wy += 2;
      wx = 1;
    }
    else wx += 2;
  }
  int by = 51, bx = 1;
  while (B > 0) {
    G.at(by).at(bx) = 1;
    B--;
    if (bx == 99) {
      by += 2;
      bx = 1;
    }
    else bx += 2;
  }
  cout << 100 << " " << 100 << endl;
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      if (G.at(i).at(j) == 0) cout << '.';
      else cout << '#';
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
c = [tuple(map(int, input().split(' '))) for _ in range(3)]


def diff(arr):
    return tuple([pre_x - x for pre_x, x in zip(arr[:-1], arr[1:])])


diffs = [diff(row) for row in c]

if diffs[0] == diffs[1] == diffs[2]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
// inputに入力データ全体が入る
function Main(input) {

console.log('%d',input%2==0?input:input*2);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 20680
N,M=map(int,input().split())
import itertools
graph={i:{} for i in range(1,N+1)}
for _ in range(M):
    a,b=map(int,input().split())
    graph[a][b]=1
    graph[b][a]=1
    
seq=[i+1 for i in range(N)]
Q=list(itertools.permutations(seq))
ans=0
for que in Q:
    flag=True
    s=que[0]
    if s!=1:
        flag=False
    for i in range(1,N):
        node=que[i]
        if node in graph[s]:
            s=node
        else:
            flag=False
        if flag==False:
            break
    ans+=int(flag)
print(ans)    

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

signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    vector < int > gay_shit = {11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381};
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cout << gay_shit[i] << ' ';
    cout << '\n';
}


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

using namespace std;

#define int long long
//region template
#define double long double
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
template<typename T1> void read(T1& arg) { cin >> arg; }
template<typename T1, typename... T2> void read(T1& arg, T2&... args) { cin >> arg; read(args...); }
#define make(t, ...) t __VA_ARGS__; read(__VA_ARGS__);
//endregion




void solve() {
    make(int, n, W);
    vector<int> w(n), v(n);
    forn (i, n) {
        cin >> w[i] >> v[i];
    }
    vector<vector<int>> dp(n, vector<int>(W + 1, -(1e9)));
    dp[0][0] = 0;
    dp[0][w[0]] = v[0];
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j <= W; ++j) {
            dp[i][j] = dp[i - 1][j];
            if (j - w[i] >= 0) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
            }
        }
    }
    cout << *max_element(all(dp[n - 1]));
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    while (cin.peek() != EOF) {
        solve();
        cout << endl << endl;
        string s;
        do getline(cin, s);
        while (!cin.eof() && !s.empty());
        while (isspace(cin.peek())) cin.get();
    }
#else
    solve();
#endif
    return 0;
}


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

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> T;
	if (T[0]==T[1]&&T[0]==T[2]) {
		cout << "Yes";
	}
	else if (T[1]==T[2]&&T[1]==T[3]) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
        long deposit = 100;
        int year = 0;
        
        while (true) {
            year++;
            deposit += deposit * 0.01;
            if (X <= deposit) {
                break;
            }
        }
        
        System.out.println(year);
    }
}


Measured memory_bytes: 35956
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

a,b=input().split()
if (a=="H" and b=="H") or (a=="D" and b=="D"):
    print("H")
else:
    print("D")

Measured memory_bytes: 38384
#include <cstdio>
#include <vector>

using namespace std;

const int N_MAX = 500;
const int M_MAX = 200000;
const int Q_MAX = 100000;

int N, M, Q;
int L[M_MAX + 1], R[M_MAX + 1];
int p[Q_MAX + 1], q[Q_MAX + 1];

int sum[N_MAX + 1][N_MAX + 1];

void solve() {
  for (int i = 0; i < Q; i++) {
    int start_at = p[i];
    int end_at = q[i];

    printf("%d\n", sum[end_at][end_at] - sum[start_at - 1][end_at]);
  }
}

int main() {
  scanf("%d %d %d", &N, &M, &Q);

  for (int i = 0; i < M; i++) {
    int start_at, end_at;
    scanf("%d %d", &start_at, &end_at);
    sum[start_at][end_at]++;
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
    }
  }

  for (int i = 0; i < Q; i++) {
    scanf("%d %d", &p[i], &q[i]);
  }

  solve();
}


Measured memory_bytes: 2560
#include<stdio.h>
 
int judging(int*,int*);
 
int main(void)
{
    int i,j,k,n,count;
    int pips[100][6],A[6],B[6];
 
    scanf("%d",&n);
    for(i = 0;i < n;i++){
        for(j = 0;j < 6;j++){
            scanf("%d",&pips[i][j]);
        }
    }
    count = 0;
    for(i = 0;i < n;i++){
        for(j =(i + 1);j < n;j++){
            for(k = 0;k < 6;k++){
                A[k] = pips[i][k];
            }
            for(k = 0;k < 6;k++){
                B[k] = pips[j][k];
            }
            count += judging(A,B);
        }
    }
    if(count > 0){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}
 
int judging(int *a,int *b)
{
    int dice[7][7] = {
        {10,2,4,1,3,10,10}
        ,{3,10,0,5,10,2,10}
        ,{1,5,10,10,0,4,10}
        ,{4,0,10,10,5,1,10}
        ,{2,10,5,0,10,3,10}
        ,{10,3,1,4,2,10,10}
        ,{10,10,10,10,10,10,10}
    };
    int i,j,c,top,front,right,judge;
 
    top = 6;
    front = 6;
    c = 0;
    for(i = 0;i < 6;i++){
        if(a[i] == b[i])c++;
    }
    for(i = 0;i < 6;i++){
        if(c >= 2){
            if(a[i] == b[0] && a[5 - i] == b[5]){
                if(a[0] == b[i] && a[5] == b[5 - i])top = i;
            }
        }
        else if(a[i] == b[0] && a[5 - i] == b[5])top = i;
    }
    for(i = 0;i < 6;i++){
        if(c >= 2){
            if(a[i] == b[1] && a[5 - i] == b[4]){
                if(a[1] == b[i] && a[4] == b[5 - i])front = i;
            }
        }
        else if(a[i] == b[1] && a[5 - i] == b[4])front = i;
    }
    right = dice[top][front];
    judge = 0;
    if(right != 10){
        j = 0;
        if(a[right] == b[2])j++;
        if(a[5 - right] == b[3])j++;
        if(a[5 - front] == b[4])j++;
        if(a[5 - top] == b[5])j++;
    }
    if(j == 4)judge = 1;
    else judge = 0;
    return judge;
}




Measured memory_bytes: 2112
#include <stdio.h>

int main(){
   int n,i;
   char s[200001],t[200001];

   scanf("%s %s",s,t);
   for (i=n=0;s[i]!='\0';i++)
      if (s[i]!=t[i]) n++;
   printf("%d\n",n);
   return 0;
}


Measured memory_bytes: 2064
tmp=input().split()
M,D=tmp[0],tmp[1]

ans=0
for m in range(1,int(M)+1):
    for d in range(1,int(D)+1):
        if d<22: continue
        tmp=str(d)
        if (int(tmp[0])>=2 and int(tmp[1])>=2 and int(tmp[0])*int(tmp[1])==m): 
            ans+=1

print(ans)

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

#define ine long long

using namespace std;

vector <int> v[100010];
bool vis[100010];

void dfs(int n)
{
	vis[n] = true;

	for(auto i:v[n])
	{
		if(!vis[i])
			dfs(i);
	}
}

int32_t main()
{
	int n,m;
	cin >> n >> m;

	int x,y,z;

	for(int i=0;i<m;i++)
	{
		cin >> x >> y >> z;

		v[x].push_back(y);
		v[y].push_back(x);
	}

	int count = 0;

	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
			dfs(i), count++;
	}

	cout << count << endl;
}


Measured memory_bytes: 8960
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    ll N,K; cin >> N >> K;
    vector<ll> A(N);
    map<ll,ll> x;
    vector<ll> t(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        x[i+1] = A[i];
    }
    ll s = 1;
    ll g = x[s];
    t[0] = s;
    ll cnt=0;
    ll ls=1;
    //cerr << s << " " << g << endl;
    for(int i=1;i<N;i++){
        s = x[s];
        g = x[s];
        t[i] = s;
        if(x.count(g)==1){
            cnt = i;
            //break;
        }
    }
    ls = t[cnt];
    ll ln=0;
    for(int i=0;i<cnt;i++){
        cerr << t[i] << "\n";
        if(t[i]==ls) ln=i;
    }
    cerr << cnt << "ls" << ls << "\t" << ln << endl;
    if(K<ln){
        cout << t[K] << endl;
    }else{
        ll num = cnt-ln;
        cerr << cnt << "-" << ln << "=" << num << endl;
        K-=ln;
        num = K%num;
        cout << t[ln+num] << endl;
    }
    return 0;
}


Measured memory_bytes: 18812
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;
const long long INF = 1LL << 60;    // 1.15x10^18

int main() {
    int n, m; cin >> n >> m;
    Graph g(n);
    while (m--) {
        int u, v, w; cin >> u >> v >> w; u--, v--;
        g[u].emplace_back(v, w);
        g[v].emplace_back(u, w);
    }
    vector<bool> seen(n);
    vector<long long> a(n), b(n);
    auto dfs = [&](auto dfs, int u) -> void {
        seen[u] = true;
        for (auto &p: g[u]) if (!seen[p.first]) {
            a[p.first] = -a[u];
            b[p.first] = p.second - b[u];
            dfs(dfs, p.first);
        }
    };
    a[0] = 1, b[0] = 0;
    dfs(dfs, 0);
    long long lb = 1LL, ub = INF, x = -1;
    for (int u = 0; u < n; u++) {
        if (a[u] ==  1) lb = max(lb, 1 - b[u]);
        if (a[u] == -1) ub = min(ub, b[u] - 1);
        for (auto &p: g[u]) {
            int v = p.first; long long w = p.second;
            long long num = a[u] + a[v];
            long long den = b[u] + b[v];
            if (num == 0) {
                if (den != w) return !(cout << 0 << endl);
            } else {
                if ((w - den) % 2) return !(cout << 0 << endl);
                long long x0 = (w - den) / num;
                if (x0 <= 0) return !(cout << 0 << endl);
                if (x == -1) x = x0;
                if (x != x0) return !(cout << 0 << endl);
            }
        }
    }
    if (x == -1) cout << max(0LL, ub - lb + 1) << endl;
    else cout << (lb <= x && x <= ub) << endl;
    return 0;
}


Measured memory_bytes: 13056
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}
 
 
int n, right_low[200005];
ll DP[200005], arr[200005];
 
 
int main(){
 
    ios_base::sync_with_stdio(0);
 
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>arr[i];
 
    stack<int> st;
    right_low[n] = n+1;
    st.push(n);
    for(int i=n-1;i>=1;i--){
        while(!st.empty() && arr[st.top()] >= arr[i])
            st.pop();
        if(st.empty())  right_low[i] = n+1;
        else    right_low[i] = st.top();
        st.push(i);
    }
 
// for(int i=1;i<=n;i++)   cout<<right_low[i]<<" ";cout<<endl;
 
    DP[n] = arr[n];
    for(int i=n-1;i>=1;i--){
        DP[i] = (right_low[i]-i)*arr[i] + DP[right_low[i]];
    }
 
    ll ans = 0;
    ans = accumulate(DP+1, DP+n+1, 0LL);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4992
N,M = list(map(int,input().split()))
MAX = 1000000000
import queue
dist = [MAX for i in range(N)]
pre = [-1 for i in range(N)]
To = [[] for i in range(N)]#indexに向かっている部屋番号の集合

que = queue.Queue()

for _ in range(M):
    a,b = list(map(int,input().split()))
    a -= 1
    b -= 1
    To[a].append(b)
    To[b].append(a)
dist[0] = 0
que.put(0)
while(not que.empty()):
    v = que.get()
    for u in To[v]:
        if pre[u] != -1: continue
        dist[u] = dist[v] + 1
        que.put(u)
        pre[u] = v
        
        
print('Yes')
for i in pre[1:N]:
    print(i+1)

Measured memory_bytes: 35908
#include<iostream>
#include<algorithm>

using namespace std;

unsigned long euclidean_gcd(unsigned long a,unsigned long b)
{
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

int main()
{
    unsigned long A,B,C,D;
    unsigned long lcm,gcm;
    unsigned long cnt_c,cnt_d,cnt_cd,cnt_tot;
    cin >> A >> B >> C >> D;

    gcm = euclidean_gcd(C,D);

    lcm = C*D/gcm;

    cnt_tot = B-(A-1);
    cnt_c = (B/C)-((A-1)/C);
    cnt_d = (B/D)-((A-1)/D);
    cnt_cd = (B/lcm)-((A-1)/lcm);

    //cout << cnt_tot << " " << cnt_c  << " " << cnt_d << " " <<  cnt_cd << endl;

    cout << cnt_tot - (cnt_c + cnt_d - cnt_cd) << endl;

}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int x,y;
  int rem=0;
  scanf("%d %d",&x,&y);
  while(true){
    rem=x%y;
    if(rem==0){
      break;
    }
    x=y;
    y=rem;
  }
  printf("%d\n",y);
  return 0;
}



Measured memory_bytes: 2720
#include<stdio.h>
#include<stdlib.h>
int main()
{
  int n,i,count=0;
  scanf("%d",&n);
  char *s = (char*)malloc(sizeof(char)*2*n);
  scanf("%s",s);
//   printf("%s",s);
  for(i=0;i<n-2;i++)
  {
    //   printf("%c %c %c",s[i],s[i+1],s[i+2]);
      if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
      {
          count++;
      }
  }
  printf("%d",count);
 return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    for(int i = 1; i <= 10000; i++){
        if(floor(i*0.08) == a && floor(i*0.1) == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}




Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())
	var isYes = false
	for i := 1; i <= 9; i++ {
		q, r := N/i, N%i
		if (q >= 1 && q <= 9) && r == 0 {
			isYes = true
			break
		}
	}
	if isYes {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int func(int x, int y) {
    int cnt = 0;
    for (int i=1; i<=x-2; ++i) {
        for (int j=i+1; j<=x-1; ++j) {
            for (int k=j+1; k<=x; ++k) {
                if ((i+j+k) == y) ++cnt;
            }
        }
    }
    return cnt;
}

int main() {
    int n,x;
    while (1) {
        cin >> n >> x;
        if (n==0 && x==0) break;
        cout << func(n,x) << endl;
    }
    return 0;
}


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

int main()
{
int x[3];
cin >> x[0];
x[2] = x[0]/3600; x[0]%=3600;
x[1] = x[0]/60; x[0]%=60;
cout << x[2] << ":" << x[1] << ":" << x[0] << endl;
return 0;
}

Measured memory_bytes: 1168
(set! *unchecked-math* true)
(defn input []
  (->> (clojure.string/split (read-line) #"\s")
    (map #(Integer/parseInt %))))

(defn ChooseIntegers [[A B C]]
  (if ((complement empty?) (eduction
                             (comp (take B)
                               (map #(unchecked-remainder-int % B))
                               (filter (partial = C))
                               (take 1))
                             (iterate (partial + A) A)))
    "YES"
    "NO"))

(->> (input)
  ChooseIntegers
  println)

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

long long MOD=1e9+7;
//a^n
using ll = long long;
long long power(long long n,long long a){
	
	if(n==0){
		return 1;
	}
	else{
		if(n%2==0){
			return ((power(n/2,a)%MOD)*(power(n/2,a)%MOD))%MOD;
		}
		long long x=power((n-1)/2,a);
		x=x%MOD;
		return ((a*((x*x)%MOD))%MOD)%MOD;
	}
	
}


void  solve(){
	
ll n;
cin>>n;
ll ans=power(n,(ll)10);

ans=(ans-power(n,9))%MOD;
if(ans<0){
	ans=ans+MOD;
}

ans=(ans-power(n,9))%MOD;
if(ans<0){
	ans=ans+MOD;
}
ans=(ans+power(n,8))%MOD;
 cout<<ans;
 
}

int main(){

	
	
		solve();
		cout<<endl;	
	
 
}


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

int main(){
    string s;
    cin >> s;
    char front = s[0], back = s[s.length()-1];
    int turn = s.length();
    if (front == back){
        turn++;
    }
    if (turn%2 == 0){
        cout << "Second" << endl;
    }else{
        cout << "First" << endl;
    }
    return 0;
}

Measured memory_bytes: 3788
// AOZ 2084: Hit and Blow
// 2017.10.2 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX 5050
 
int cand[3][MAX], sz[3];

int nhit(int a, int b) 
{  
    int i, k = 0;

	for (i = 0; i < 4; i++) {
		if (a%10 == b%10) k++;
		a /= 10, b /= 10;
	}
	return k; 
}  
  
int nblow(int a, int b)  
{  
    int i, j, k = 0;
	int aa, bb;

    for (i = 0; i < 4; i++) {
		aa = a % 10, a /= 10, bb = b;
		for (j = 0; j < 4; j++) {
			if (i != j && bb%10 == aa) k++;
			bb /= 10;
		}
	}
    return k;  
}  
  
int diff(int a)
{
	int i;
	static int c = 0;
	int f[10];
  
	c++;
	for (i = 0; i < 4; i++) {  
        if (f[a % 10] == c) return 0;
		f[a % 10] = c;
        a /= 10;
    }
    return 1;  
}  
  
int main()  
{  
    int n, i, j, k1, k2, num, hit, blow;
	int hb[5][5], c;

	for (j = 0, i = 123; i <= 9876; i++) if (diff(i)) cand[2][j++] = i;
	sz[2] = j;

	while (scanf("%d", &n) && n > 0) {
		for (k1 = 2, k2 = 0; n-- > 0; k1 = k2, k2 = !k2) {
			scanf("%d%d%d", &num, &hit, &blow);
			for (sz[k2] = 0, i = 0; i < sz[k1]; i++) 
				if (nhit(cand[k1][i], num) == hit && nblow(cand[k1][i], num) == blow)
					cand[k2][sz[k2]++] = cand[k1][i];
        }
		if (sz[k1] == 1) { printf("%04d\n",cand[k1][0]); goto Done; }
		if (sz[k1] > 1 && sz[k1] <= 24) {
			memset(hb, 0, sizeof(hb));
			for (c = 1, j = 0; j < sz[2]; j++, c++) {
				for (i = 0; ; i++) {
					if (i == sz[k1]) { printf("%04d\n", cand[2][j]); goto Done; }
					hit  =  nhit(cand[k1][i], cand[2][j]);
					blow = nblow(cand[k1][i], cand[2][j]);
					if (hb[hit][blow] == c) break;
					hb[hit][blow] = c;
				}
			}
        }
		puts("????");
Done:;
    }  
    return 0;  
}  

Measured memory_bytes: 1764
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int A = nextInt();
		int B = nextInt();

		int ans = 0;
		for(int i=A;i<=B;i++){
			String s = String.valueOf(i);
			int h=0;
			int t=s.length()-1;
			while(h<=t){
				if(s.charAt(h)!=s.charAt(t)){
					break;
				}
				h++;
				t--;
			}
			if(h>t){
				ans++;
			}
		}

		System.out.println(ans);

	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 24788
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include <random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ");
//#define double long double

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int MAX = 200060;
const double pi = acos(-1);
const ll INF = 1e16;


ll d[303][303];
ll dist[303][303];
void solve() {
	int N, M, L; cin >> N >> M >> L;
	REP(i, N) {
		REP(j, N) {
			d[i][j] = INF;
			d[j][i] = INF;
			dist[i][j] = INF;
			dist[j][i] = INF;
		}
	}
	REP(i, M) {
		int A, B, C; cin >> A >> B >> C;
		A--, B--;
		if (C <= L) {
			d[A][B] = C;
			d[B][A] = C;
		}
	}
	REP(k, N) {	//kが中継点
		REP(i, N) {
			REP(j, N) {
				d[i][j] = min(d[i][j], (d[i][k] + d[k][j]));
			}
		}
	}
	REP(i, N) {
		REP(j, N) {
			if (d[i][j] <= L)dist[i][j] = 1;
		}
	}
	REP(k, N) {	//kが中継点
		REP(i, N) {
			REP(j, N) {
				dist[i][j] = min(dist[i][j], (dist[i][k] + dist[k][j]));
			}
		}
	}
	int Q; cin >> Q;
	while (Q--) {
		int s, t; cin >> s >> t; s--, t--;
		int cost = dist[s][t];
		//print(cost);
		if (cost >= INF)print(-1)
		else print(cost-1);
	}
}


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

	solve();
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std; 
char s[4005];
vector<int> r,g,b;
typedef vector<int>::iterator vi;
int main()
{
	int n;
	long long sum = 0;
	vi v1, v2, v3, v;
	scanf("%d", &n);
	scanf("%s", s);
	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'R')
			r.push_back(i + 1);
		else if(s[i] == 'G')
			g.push_back(i + 1);
		else
			b.push_back(i + 1);
	}
	sort(r.begin(), r.end());
	sort(g.begin(), g.end());
	sort(b.begin(), b.end());
		for(v1 = r.begin(); v1 != r.end(); v1++)
		{
			int i = (*v1) - 1;
			v2 = upper_bound(g.begin(), g.end(), i + 1);
			for(v = v2; v < g.end(); v++)
			{
				sum += b.size() - (upper_bound(b.begin(), b.end(), *v) - b.begin());
				if(find(b.begin(), b.end(), 2 * *v - i - 1) != b.end())
					sum--;
			}
			v2 = upper_bound(b.begin(), b.end(), i + 1);
			for(v = v2; v < b.end(); v++)
			{
				sum += g.size() - (upper_bound(g.begin(), g.end(), *v) - g.begin());
				if(find(g.begin(), g.end(), 2 * *v - i - 1) != g.end())
					sum--;
			}
		}
		for(v1 = g.begin(); v1 != g.end(); v1++)
		{
			int i = (*v1) - 1;
			v2 = upper_bound(r.begin(), r.end(), i + 1);
			for(v = v2; v < r.end(); v++)
			{
				sum += b.size() - (upper_bound(b.begin(), b.end(), *v) - b.begin());
				if(find(b.begin(), b.end(), 2 * *v - i - 1) != b.end())
					sum--;
			}
			v2 = upper_bound(b.begin(), b.end(), i + 1);
			for(v = v2; v < b.end(); v++)
			{
				sum += r.size() - (upper_bound(r.begin(), r.end(), *v) - r.begin());
				if(find(r.begin(), r.end(), 2 * *v - i - 1) != r.end())
					sum--;
			}
		}
		for(v1 = b.begin(); v1 != b.end(); v1++)
		{
			int i = (*v1) - 1;
			v2 = upper_bound(g.begin(), g.end(), i + 1);
			for(v = v2; v < g.end(); v++)
			{
				sum += r.size() - (upper_bound(r.begin(), r.end(), *v) - r.begin());
				if(find(r.begin(), r.end(), 2 * *v - i - 1) != r.end())
					sum--;
			}
			v2 = upper_bound(r.begin(), r.end(), i + 1);
			for(v = v2; v < r.end(); v++)
			{
				sum += g.size() - (upper_bound(g.begin(), g.end(), *v) - g.begin());
				if(find(g.begin(), g.end(), 2 * *v - i - 1) != g.end())
					sum--;
			}
		}
	printf("%lld\n", sum);
	return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a==b){
        cout << "Draw" << endl;
    }
    else if((a>b || a == 1)&&b!=1){
        cout << "Alice"  << endl;
    }
    else{
        cout << "Bob" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
	long long n, k,a[1000000],count1,an1,an2;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] == 1)count1 = i;
	}
	if ((n - count1) % (k - 1) != 0)an1 = (n - count1) / (k - 1) + 1;
	else an1 = (n - count1) / (k - 1);
	if ((count1 - 1) % (k - 1) != 0)an2 = (count1 - 1) / (k - 1) + 1;
	else an2 = (count1 - 1) / (k - 1);
	if ((n - 1) % (k-1) == 0)cout <<(n-1)/(k-1) << endl;
	else cout <<(n-1)/(k-1)+1<< endl;
	getchar();
	getchar();
	return 0;
}

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

const int mod = 2019;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    reverse(s.begin(), s.end());
    int x = 1;
    vector<int> cnt(mod);
    int tot = 0;
    ll ans = 0;
    rep(i, n){
        cnt[tot]++;
        tot += (s[i] - '0') * x;
        tot %= mod;
        x *= 10;
        x %= mod;
        ans += cnt[tot];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7, maxm = 200 + 7;
const long long mod = 998244353;
long long n;
int a[maxn], prime[maxm], hs[maxm], d;
int num[maxm], t, ok[maxm], tmp[maxm];
long long v[maxm], ans, mi[maxn];
char s[maxn];

void p_dfs(int pos, int x) {
	if(pos > d) {
		num[++t] = n / x;
		ok[t] = 1;
		return;
	}
	p_dfs(pos + 1, x);
	if(prime[pos] > 2) {
		for (int i = 1; i <= hs[pos]; ++i) {
			x = x * prime[pos];
			p_dfs(pos + 1, x);
		}
	}
}

void dfs(int pos) {
	if(pos < 0) {
		for (int i = t; i; --i) if(ok[i]) {
			ans = (ans + v[i]) % mod;
		}
		return;
	}
	if(a[pos]) {
		for (int i = 1; i <= t; ++i) {
			if(ok[i] && (n - pos <= num[i] || a[pos + num[i]] == 1)) tmp[i] = 1;
			else tmp[i] = 0;
		}
		for (int i = 1; i <= t; ++i) {
			if(!tmp[i]) continue;
			int len = n - pos;
			if(len > num[i]) ans = (ans + v[i]) % mod;
			else ans = (ans + v[i] * mi[num[i] - len]) % mod;
		}
	}
	for (int i = 1; i <= t; ++i) {
		if(ok[i]) {
			if(n - pos <= num[i] || a[pos + num[i]] != a[pos]) ok[i] = 1;
			else ok[i] = 0;
		}
	}
	dfs(pos - 1);
}

int main() {
	scanf("%lld", &n);
	scanf("%s", s + 1);
	int l = strlen(s + 1);
	for (int i = 1; i <= l; ++i) a[l - i] = s[i] - '0';
	mi[0] = 1; for (int i = 1; i <= n; ++i) mi[i] = mi[i - 1] * 2 % mod;
	int p = n;
	for (int i = 2; i <= n; ++i) {
		if(p % i) continue;
		prime[++d] = i;
		while(p % i == 0) {
			p /= i; ++hs[d];
		}
	}
	p_dfs(1, 1);
	sort(num + 1, num + t + 1);
	for (int i = t; i; --i) {
		v[i] = num[i] * 2;
		for (int j = i + 1; j <= t; ++j) if(num[j] % num[i] == 0) {
			v[i] = (v[i] - v[j] + mod) % mod;
		}
	}
	dfs(n - 1);
	printf("%lld\n", ans % mod);
	return 0;
}

Measured memory_bytes: 6276
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N,K;
  cin >> N >> K;
  
  vector<long long>a(N);
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  
  long long ans = 0;
  long long sum = 0;
  
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      int t = 0;
      int s = 0;
      if(j < i && a[j] < a[i]) s++;
      if(j > i && a[j] < a[i]) t++;
      //cout << s << t <<endl;
      if(t > 0){
          if(K % 2 == 0){
          sum += K / 2;
          sum %= 1000000007;
          sum *= K + 1;
          sum %= 1000000007;
          sum *= t;
          sum %= 1000000007;
          ans += sum;
          ans %= 1000000007;
          sum = 0;
      }
      else{
          sum += (K + 1)/ 2;
          sum %= 1000000007;
          sum *= K;
          sum %= 1000000007;
          sum *= t;
          sum %= 1000000007;
          ans += sum;
          ans %= 1000000007;
          sum = 0;
      }
      }
      if(s > 0){
          if(K % 2 == 0){
      sum += K / 2;
      sum %= 1000000007;
      sum *= (K - 1);
      sum %= 1000000007;
      sum *= s;
      sum %= 1000000007;
      ans += sum;
      //cout << sum << endl;
      ans %= 1000000007;
      sum = 0;
      }
      else{
          sum += (K - 1) / 2;
      sum %= 1000000007;
      sum *= K;
      sum %= 1000000007;
      sum *= s;
      sum %= 1000000007;
      ans += sum;
      ans %= 1000000007;
      sum = 0;
      }
      }
  //cout << ans << endl;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

        

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = s; i < (int)(n); i++)
#define print(a) cout << (a) << endl; 
typedef long long ll;
const int MOD = 1000000007; 

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    string s; 
    cin >> s;
    int pass = 0, bpass = 0;
    for (char c: s) {
        string o = "No";
        if (c == 'a') {
            if (a+b > pass) {
                ++pass;
                o = "Yes";
            } 
        } 
        if (c == 'b') {
            if (a+b > pass && b > bpass) {
                ++pass;
                ++bpass;
                o = "Yes";
            }
        }
        cout << o << endl; 
    }
    return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define ll long long
const int maxn = 100005;
using namespace std;

int main()
{
    ll x,y,z;
    cin >> x >> y >> z;
    double sum = x - z;
    ll ans;
    sum = sum /  (y + z);
    ans = (int )sum;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

void solve(long long N, long long K){
    if (K == 0) {
        std::cout << N*N << std::endl;
    } else {
        long long ret = 0;
        for (int i = K+1; i < N+1; i++) {
            long long a = (N/i)*(i-K) + max(0LL, (N%i) - (K-1));
            ret += a;
        }
        std::cout << ret << std::endl;
    }
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    long long K;
    long long N;
    scanf("%lld",&N);
    scanf("%lld",&K);
    solve(N, K);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <map>
using namespace std;

int main(){
    string str;
    map<int,int> bm,am;
    int num,day;
    char ch; //,
    
    while(getline(cin,str)&&str.size() > 0){
        stringstream s1(str);
        s1 >> num >> ch >> day;
        ++bm[num];
    }
    
    while(getline(cin,str)){
        stringstream s2(str);
        s2 >> num >> ch >> day;
        ++am[num];
    }
    
    for(map<int,int>::iterator it = bm.begin() ; it != bm.end() ; ++it){
        if(am[(*it).first]){
            cout << (*it).first << " " << (*it).second+am[(*it).first] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1224
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define int long long
using namespace std;
long double inf = 1e18;

int32_t main()
{
	long double a,b;
	cin>>a>>b;
	long double c = a*b;
	int d = floor(c);
	cout<<d<<endl;
	return 0;
} 

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
int n,a[1010101];
main () {
	cin >>n;
	for (int i = 1; i <= n; i++)
		cin >>a[i];
	int ans = 0,mx = -1e9;
	for (int i = 2; i <= n; i++) {
		if (a[i] <= a[i - 1]) {
			ans++;
		}
		else
		{
			mx = max(ans,mx);
			ans = 0;
		}
	}
	mx = max(ans,mx);
	if (mx == -1e9) {
		cout <<0;
	}
	else
	cout <<mx;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
	string s; cin >> s;
	int a = (s[0]-'0')*10 + (s[1]-'0');
	int b = (s[2]-'0')*10 + (s[3]-'0');
	if(a>12 || a==0){
		if(b>12 || b==0){
			cout << "NA";
		}else{
			cout << "YYMM";
		}
	}else{
		if(b>12 || b==0){
			cout << "MMYY";
		}else{
			cout << "AMBIGUOUS";
		}
	}
	cout <<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define x first
#define y second
#define PII pair<int,int>
#define show(x) cerr << #x << " = " << x << '\n'
using namespace std;
int main(int argc,char *argv[]){
    ios::sync_with_stdio(false);
    string s;
    int q,k,u;
    char c;
    cin >> s >> q;
    int flag = 0;
    while(q --){
        cin >> u;
        if(u == 1){
            flag++;
        }
        else{
            cin >> k >> c;
            if(flag % 2 == 0){
                if(k == 1) s.insert(s.begin(),c);
                else s.insert(s.end(),c);
            }
            else{
                if(k == 1) s.insert(s.end(),c);
                else s.insert(s.begin(),c);
            }
        }
    }
    if(flag % 2 == 1) reverse(s.begin(),s.end());
    cout << s;
    return 0;
}


Measured memory_bytes: 912