akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,m;
int a[100100];
pair<int,int> cb[100100];
ll ans=0;



int main(){
	cin>>n>>m;
	REP(i,n)
		cin>>a[i];
	
	REP(i,m){
		int b,c;
		cin>>b>>c;
		cb[i]=pair<int,int>(c,b);
	}
	
	sort(a,a+n);
	sort(cb,cb+m);
	int count=0;
	int wh=m;
	for(int i=0;i<n;i++){
		if(count==0){
			wh--;
			count=cb[wh].second;
		}
		if(cb[wh].first>=a[i]){
			a[i]=cb[wh].first;
		}else{
			break;
		}
		count--;
	}
	for(int i=0;i<n;i++){
		ans+=(ll)a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <map>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main(void) {
  string S;
  cin >> S;
  map<char, int> word;
  for (auto c : S) {
    word[c]++;
  }
  for (auto& d : word) {
    if (d.second % 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	int n3 = n * 3;
	vector<long long> a(n3);

	

	for (int i = 0; i < n3; i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end(),greater<int>());

	long long sum = 0;
	int j = 1;
	for (int i = 0; i < n; i++) {
		sum += a[j];
		j = j + 2;
	}
	
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 2560
// Template Headers {{{
#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<long long>; using vvll = vector<vll>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}
// Preprocessing & "Global" variables {{{
struct Solver {
	Solver() {}
	int solve();
};
// }}}

int Solver::solve() {
	int M = 1000;
	int n; cin >> n;
	cout << (M - n % M) % M << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	Solver solver;
	#ifdef JUDGE_MULTI_CASE
		int t; cin >> t; for (int i = 1; i <= t; i++)
	#endif
	solver.solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

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

// vim: fdm=marker


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int cnt = 0;
    int tmp = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
            tmp++;
            cnt = max(tmp, cnt);
        } else {
            tmp = 0;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;

int n;
int p[11];
int main(){
    cin >> n;

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

    sort(p, p+n);
    sum -= p[n-1]/2;

    cout << sum << endl;
}


Measured memory_bytes: 256
from scipy import misc
n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
s=sorted(s)
ans=0
c=1
t=s[0]
for i in range(1,n):
    if t==s[i]:
        c+=1
    else:
        ans+=misc.comb(c,2,True)
        t=s[i]
        c=1
ans+=misc.comb(c,2,True)
print(ans)

Measured memory_bytes: 21772
N = int(input())
A = list(map(int, input().split()))

ans = 0
res = 1

for i in range(N-1):
    if A[i+1] != A[i]:
        ans += res//2
        res = 1
        
    else:
        res += 1
        
ans += res//2

print(ans)

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

int main(){
  int H, W;
  cin >> H >> W;
  char A[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> A[i][j];
    }
  }
  for(int i=0;i<H;i++){
    bool ans = true;
    for(int j=0;j<W;j++){
      if(A[i][j] == '#') ans = false;
    }
    if(ans){
      for(int j=0;j<W;j++){
        A[i][j] = '1';
      }
    }
  }

  for(int i=0;i<W;i++){
    bool ans = true;
    for(int j=0;j<H;j++){
      if(A[j][i] == '#') ans = false;
    }
    if(ans){
      for(int j=0;j<H;j++){
        A[j][i] = '1';
      }
    }
  }
  for(int i=0;i<H;i++){
    bool ans1 = false;
    for(int j=0;j<W;j++){
      if(A[i][j] == '.' || A[i][j] == '#'){
        cout << A[i][j];
        ans1 = true;
      }
    }
    if(ans1) cout << endl;
  }
}

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


int main(){

    int A, B;
    int S, T, U, V;
    int ans = 0;
    cin >> A >> B;
    for(int i=A; i<=B; i++){

        T = i % 10;
        S = i / 10000 % 10;
        U = i /1000 % 10;
        V = i /10 % 10;
        if(S == T && U ==V){
            ans++;
        }

    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  int H, W; cin >> H >> W;
  char S[H][W];
  int L[H][W], R[H][W], U[H][W], D[H][W];
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      cin >> S[i][j];
      L[i][j] = R[i][j] = D[i][j] = U[i][j] = 1;
    }
  }
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      if(S[i][j] == '#') {
        L[i][j] = 0;
        D[i][j] = 0;
      } else if(i == 0 && j == 0) {
        L[i][j] = 1;
        D[i][j] = 1;
      } else if(i == 0) {
        L[i][j] = L[i][j-1] + 1;
        D[i][j] = 1;
      } else if(j == 0) {
        L[i][j] = 1;
        D[i][j] = D[i-1][j] + 1;
      } else {
        L[i][j] = L[i][j-1] + 1;
        D[i][j] = D[i-1][j] + 1;
      }
    }
  }

  for(int i = H-1; i >= 0; --i) {
    for(int j = W-1; j >= 0; --j) {
      if(S[i][j] == '#') {
        R[i][j] = 0;
        U[i][j] = 0;
      } else if(i == H-1 && j == W-1) {
        U[i][j] = 1;
        R[i][j] = 1;
      } else if(i == H-1) {
        U[i][j] = 1;
        R[i][j] = R[i][j+1] + 1;
      } else if(j == W-1) {
        U[i][j] = U[i+1][j] + 1;
        R[i][j] = 1;
      } else {
        R[i][j] = R[i][j+1] + 1;
        U[i][j] = U[i+1][j] + 1;
      }
    }
  }
  int maxN = -1;
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      maxN = max(maxN, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);
    }
  }
  cout << maxN << endl;

  return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<char> s(n);
  int count = 0;
  rep(i, n) {
    cin >> s.at(i);
  }
  rep(i, n - 2) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
      count++;
    }
  }
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int w = sc.nextInt();
		int h = sc.nextInt();
		int n = sc.nextInt();

		int wmin = 0, wmax = w;
		int hmin = 0, hmax = h;
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int a = sc.nextInt();

			if (a == 1) {
				wmin = Math.max(wmin, x);
			} else if (a == 2) {
				wmax = Math.min(wmax, x);
			} else if (a == 3) {
				hmin = Math.max(hmin, y);
			} else {
				hmax = Math.min(hmax, y);
			}
		}

		w = Math.max(0, wmax - wmin);
		h = Math.max(0, hmax - hmin);
		System.out.println(w * h);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 10452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 5;
set<int> si;
map<int, int> mii;
int prime[maxn], sieve[maxn], cnt;
void init()
{
    prime[1] = 1;
    for (int i = 2; i < maxn; ++i){
        if (!prime[i]) sieve[++cnt] = i;
        for (int j = 1; j <= cnt && i * sieve[j] < maxn; ++j){
            prime[i * sieve[j]] = 1;
            if (i % sieve[j] == 0) break;
        }
    }
    for (int i = 1; i <= cnt; ++i) mii[sieve[i]] = i;
    return ;
}
int pan = (1 << 30) - 1;
bool dis(int x)
{
    int cur = 0;
    bool is = true;
    for (int i = 1; i * i <= x && i <= cnt; ++i){
        int p = sieve[i];
        if (x % p == 0){
            while (x % p == 0) x /= p;
            if (si.count(p)) is = false;
            else si.insert(p);
            cur |= (1 << (i - 1));
        }
    }
    if (x != 1){
        if (si.count(x)) is = false;
        else si.insert(x);
        cur |= (1 << (mii[x] - 1));
    }
    pan &= cur;
    return is;
}
int main()
{
    init();
    bool pc = true;
    int n, x;
    cin >> n;
    for (int i = 0; i < n; ++i){
        cin >> x;
        if (!dis(x)) pc = false;
    }
    if (pc) cout << "pairwise coprime" << endl;
    else if (!pan) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
    return 0;
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;

const ll mod = 1000000007;
const int N = 212345;
vi fac, cnt(N), dp(N), ans(N);
vvi g(N);

ll modpow(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b&1) ans *= a;
    a *= a;
    ans %= mod;
    a %= mod;
    b >>= 1;
  }
  return ans;
}

ll inv(ll x) { return modpow(x, mod-2); }

void dfs0(int u=1, int p=1) {
  trav(v, g[u]) if (v!=p) {
    dfs0(v, u);
    cnt[u] += cnt[v]+1;
  }
}

void dfs1(int u=1, int p=1) {
  dp[u] = fac[cnt[u]] % mod;
  trav(v, g[u]) if (v!=p) {
    dfs1(v, u);
    dp[u] *= inv(fac[cnt[v]+1]); dp[u] %= mod;
    dp[u] *= dp[v]; dp[u] %= mod;
  }
}

int n;
void dfs2(int u=1, int p=1) {
  if (u==p) ans[u] = dp[u];
  else {
    ans[u] = ans[p];
    ans[u] *= fac[n-cnt[u]-2]; ans[u] %= mod;
    ans[u] *= inv(dp[u]); ans[u] %= mod;
    ans[u] *= fac[cnt[u]+1]; ans[u] %= mod;

    ans[u] *= inv(fac[n-cnt[u]-1]); ans[u] %= mod;

    trav(v, g[u]) if (v!=p) {
      ans[u] *= inv(fac[cnt[v]+1]); ans[u] %= mod;
      ans[u] *= dp[v]; ans[u] %= mod;
    }
  }

  trav(v, g[u]) if (v!=p) {
    dfs2(v, u);
  }
}

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

  fac.pb(1);
  rep(i,1,N+1) fac.pb((fac.back()*i)%mod);

  cin >> n;

  rep(i,0,n-1) {
    int a, b;
    cin >> a >> b;
    g[a].pb(b);
    g[b].pb(a);
  }

  dfs0();
  dfs1();
  dfs2();

  rep(i,1,n+1) cout << ans[i] << '\n';

}

Measured memory_bytes: 21616
S = list(input())
n = {}
for s in S:
    n[s] = 0
for s in S:
    n[s] += 1
ans = 'Yes'
if len(n.keys()) == 2:
    for i in n.values():
        if i != 2:
            ans = 'No'
else:
    ans = 'No'
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int n;
	cin>>n;
	cout<<(n/2)*((n/2)+(n%2?1:0))<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
 
using namespace std;
 
int mod_num_counter[2030];
 
int main()
{
  //fill(mod_num_counter,mod_num_counter+2030,0);
  
  int k,a,b;
  cin >> k >> a >> b;
  
  bool ok = false;
 
  for (int i = 1; i <= 1000; i++)
  {
      int t = k * i;
      if(a<=t&&t<=b)
      {
          ok = true;
          break;
      }
  }

  if(ok)
  {
      cout << "OK" << endl;
  }
    else
    {
        cout << "NG" << endl;
    }
    
  return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#define rep(i,f,t) for(int i=f;i<t;i++)
#define repd(i,f,t) for(int i=f;i>=t;i--)
using namespace std;
int main(){
	string s;
	cin>>s;
	int q;
	cin>>q;
	vector<char> vec[2];
	int t=0;
	while(q--){
		int p;
		cin>>p;
		if(p==1)t=1-t;
		else{
			int a;char c;
			cin>>a>>c;
			a--;
			vec[a^t].push_back(c);
		}
	}
	string p="";
	repd(i,vec[0].size()-1,0)p+=vec[0][i];
	p+=s;
	rep(i,0,vec[1].size())p+=vec[1][i];
	if(t==1)reverse(p.begin(),p.end());
	cout<<p<<endl;
	return 0;
}

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

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut a: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    let mut ans: usize = 0;
    for i in 1..n {
        if a[i] < a[i - 1] {
            ans += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    }
    ans.to_string()
}


Measured memory_bytes: 5636
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

ll h, w;
vector<string> board;

ll calc_max(pair<ll, ll> start) {
    ll maxn = 0;
    vvll wl(h, vll(w));
    rep(i, h) rep(j, w) {
        if (board[i][j] == '#') wl[i][j] = -1;
        else wl[i][j] = inf;
    }

    wl[start.second][start.first] = 0;
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> que;
    que.push(start);

    while (!que.empty()) {
        auto point = que.top(); que.pop();
        ll x = point.first, y = point.second;
        rep(i, 4) {
            int nx = point.first + dx[i];
            int ny = point.second + dy[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h && wl[ny][nx] != -1 && wl[y][x] + 1 < wl[ny][nx]) {
                wl[ny][nx] = wl[y][x] + 1;
                que.push({nx, ny});
            }
        }
    }
    rep(i, h) {
        rep(j, w) {
            if (maxn < wl[i][j] && wl[i][j] != -1 && wl[i][j] != inf) maxn = wl[i][j];
        }
    }
    return maxn;
}

int main()
{
    cin >> h >> w;
    board.resize(h);
    rep(i, h) cin >> board[i];
    ll max_num = 0;
    rep(y, h) {
        rep(x, w) {
            if (board[y][x] == '#') continue;
            max_num = max(max_num, calc_max({x, y}));
        }
    }
    cout << max_num << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	num, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return num
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	a := nextInt()
	s := nextString()

	if a >= 3200 {
		fmt.Println(s)
	} else {
		fmt.Println("red")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
void run();
signed main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13); run(); }
mt19937 rng(random_device{}());

void run() {
    int n;
    cin >> n;
    set<int> a;
    for (int i = 0; i < n; ++i) {
        int b;
        cin >> b;
        if (a.count(b)) {
            cout << "NO";
            cout << endl;
            return;
        }
        a.insert(b);
    }
    cout << "YES"; cout << endl;
}


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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(void) {

    string S; cin >> S;
    char prev_color = S[0];
    int cnt = 0;
    for (int i = 1; i < S.size(); i++) {
        if (prev_color != S[i]) cnt++;
        prev_color = S[i];
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 512
n,m = map(int, input().split())
a = [];b=[];c=[];d=[]
for i in range(n):
    x,y = map(int, input().split())
    a.append(x)
    b.append(y)
for i in range(m):
    x,y = map(int, input().split())
    c.append(x)
    d.append(y)
    
for i in range(n):
    min_dist=abs(a[i]-c[0])+abs(b[i]-d[0])
    checkpoint=1
    for j in range(1,m):
        cur_dist=abs(a[i]-c[j])+abs(b[i]-d[j])
        if min_dist>cur_dist:
            min_dist = cur_dist
            checkpoint = j+1
    print(checkpoint)

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

vector< vector<int> > G(50, vector<int>(50));
vector<int> check(50);
int N, M;
void dfs(int s, int i, int j) {
    for (int k = 0; k < N; k++) {
        if (s == k) continue;
        if (s == i && k == j) continue;
        if (s == j && k == i) continue;
        if (G[s][k] == 1 && check[k] == 0) {
            check[k] = 1;
            dfs(k, i, j);
        }
    }
}

int main() {
    cin >> N >> M;
    int a, b;
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        a--; b--;
        G[a][b] = G[b][a] = 1;
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            if (G[i][j] == 0) {
                continue;
            }
            for (int k = 0; k < N; k++) check[k] = 0;
            dfs(i, i, j);
            if (check[j] == 0) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> p;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;
ll f(ll n) {
  ll res1, res2;
  for(ll i = 1; i * i <= n; ++i) {
    if(n % i == 0) {
      res1 = i;
      res2 = n / i;
    }
  } 
  return res1 + res2 - 2;
}

int main(){
  ll n;
  cin >> n;
  ll ans = f(n);
  cout << ans << endl;
}


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

typedef long long ll;

ll mod_pow(ll x,ll n,ll mod){
  ll res=1;
  while(n){
    if(n%2) res=res*x%mod;
    x=x*x%mod;
    n/=2;
  }
  return res;
}

bool miller_rabin(int n){
  
  if( n == 2 ) return true;
  
  if( n == 1 || n % 2 == 0 ) return false;
  
  int s = 0, d = n - 1;
  
  random_device rd;
  
  while( d % 2 == 0 ) s++, d /= 2;
  
  int cnt = 10;
  
  while(cnt--){
    
    int a = rd() % ( n - 1 ) + 1;
    
    int t = d;
    
    int y = mod_pow( a, t, n );
    
    while( t != n - 1 && y != 1 && y != n - 1 ){
      y = ( y * y ) % n;
      t *= 2;
    }
    
    if( y != n - 1 && t % 2 == 0 ) return false;
    
  }
  
  return true;
}

int f(int x, int n){
  int c = 5;
  return ( x * x + c ) % n;
}

int pollards_rho(int n){
  
  int y = rand() % ( n + 1 );
  int r = 1, q = 1, m = rand() + 1;

  int g, ys, x;
  
  do{
    
    x = y;
    
    for(int i=1;i<=r;i++) y = f( y, n );
    
    int k = 0;
    
    do{
      
      ys = y;
      
      for(int i=1;i<=min( m, r - k );i++){
	y = f( y, n );
	q = ( q * abs( x - y ) ) % n;
      }
      
      g = __gcd( q, n );
      k = k + m;
      
    }
    while( k < r && g <= 1 );
    
    r = 2 * r;
    
  }
  while( g <= 1 );
  
  if( g == n ){
    
    do{
      ys = f( ys, n );
      g = __gcd( abs( x - ys ), n );
    }
    while( g <= 1 );
    
  }
    
  return g;
}

vector<int> factorial(int n){
  
  vector<int> res;
  
  while( miller_rabin(n) == false ){
    
    int r = pollards_rho(n);
    
    if( 1 < r && r < n && miller_rabin(r) == true ){
      res.push_back( r );
      n /= r;
    }
    
  }
  
  if( n != 1 ) res.push_back( n );
  
  sort( res.begin(), res.end() );
  
  return res;
}

signed main(){
  
  int n;
  cin>>n;
    
  vector<int> ans = factorial(n);

  cout<<n<<": ";
    
  for(int i=0;i<(int)ans.size();i++){
    if(i) cout<<' ';
    cout<<ans[i];
  }
    
  cout<<endl;
  
  return 0;
}



Measured memory_bytes: 3168
/* Author- Abhijeet Trigunait */

#include<bits/stdc++.h>
#define lld long long int
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
#define mod 1e9+7
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define gcd(x,y) __gcd(x,y)
#define endl '\n'

using namespace std;
lld dp[3005][3005];

string getStr(string& s1, string& s2, lld len) {
	string lcs;
	lld i = 0, j = 0;
	while (len > 0) {
		if (s1[i] == s2[j]) {
			lcs.pb(s1[i]);
			++i;
			++j;
			--len;
		} else {
			if (dp[i][j + 1] > dp[i + 1][j]) {
				++j;
			} else ++i;
		}
	}
	return lcs;
}

lld getLength(string& s1, string& s2, lld i, lld j) {
	if (i >= s1.length() or j >= s2.length())return 0;
	if (dp[i][j] != -1)return dp[i][j];

	if (s1[i] == s2[j]) {
		return dp[i][j] = 1 + getLength(s1, s2, i + 1, j + 1);
	} else {
		return dp[i][j] = max(getLength(s1, s2, i, j + 1), getLength(s1, s2, i + 1, j));
	}
}


string solve(string s1, string s2) {
    memset(dp,-1,sizeof(dp));
	lld len = getLength(s1, s2,0,0);
	return getStr(s1, s2, len);
}


int main() {


	string s1, s2;
	cin >> s1 >> s2;
	cout << solve(s1, s2) << endl;
}

Measured memory_bytes: 74488
import scala.collection.mutable._
import io.StdIn.readLine

object Main extends App {
  val map = new HashMap[String,Int]
  val s = readLine.split(" ")
  s.foreach(e => {
    if(!map.contains(e)) map.put(e,1)
    else map.put(e,map(e)+1)
  })
  val maxF = map.maxBy(_._2)._1
  val maxL = s.map(e => (e.length, e)).max._2

  println(maxF + " " + maxL)
}


Measured memory_bytes: 43772
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
   ll a,b,c,d,e;
   cin>>a>>b;
   c=a+b;
   d=a-b;
   e=a*b;
   cout<<max({c,d,e})<<endl;


    return 0;
}


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc127_a
{
    class Program
    {
        public static void Main()
        {
            int[] args = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            if (args[0] > 12)
                Console.WriteLine(args[1]);
            else if (args[0] > 5)
                Console.WriteLine(args[1] / 2);
            else
                Console.WriteLine(0);

            Console.Read();
        }

    }
}


Measured memory_bytes: 11348
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.math.BigDecimal;

public class Main {
  static InputReader in;
  static PrintWriter out;

  static class Solution {
    void solve() throws IOException {
      int N = in.nextInt();
      int[] A = new int[N];
      for (int i = 0; i < N; i++) {
        A[i] = in.nextInt();
        out.print(A[i]);
        if (i != N - 1) {
            out.print(" ");
          } else {
            out.print("\n");
          }
      }
      
      insertionSort(A, N);
     
//      End solve()
    }
    
    void insertionSort(int[] A, int N) {
      for (int i = 1; i < N; i++) {
        int v = A[i];
        int j = i - 1; 
        while (j >= 0 && A[j] > v) {
          A[j+1] = A[j];
          j--;
        }
        A[j+1] = v;
        
        for (int k = 0; k < N; k++) {
          out.print(A[k]);
          if (k != N - 1) {
            out.print(" ");
          } else {
            out.print("\n");
          }
        }
      }
    
    }
//    End Solution
}


  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}


  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }

  }

}

Measured memory_bytes: 26460
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;
const double PI = acos(-1);

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	for (int i = 1; i <= 5; i++) {
		int x; cin >> x;
		if (x != i) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3508
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N; cin>>N;
	int A=0,B=0,C=0;
	for(int i=0;i<N;i++){
		int a,b,c; cin>>a>>b>>c;
		a+=max(B,C); b+=max(A,C); c+=max(A,B);
		A=a; B=b; C=c;
	}
	cout<<max({A, B, C})<<"\n";
}


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

int main() {
    
    int a, b;
    cin>>a>>b;
    
    while(1) {
        if(a == 0 && b == 0) break;
        
        if(b < a)  cout<<b<<' '<<a<<endl;
        if(a <= b) cout<<a<<' '<<b<<endl;
        cin>>a>>b;
    }
    
    return 0;
}



Measured memory_bytes: 3080
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int32_t N;
  cin >> N;
  vector<int32_t> A(N);
  vector<int32_t> B(N);
  for (int32_t i = 0; i < N; ++i) {
    cin >> A[i];
    B[i] = A[i];
  }
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  for (int32_t i = 0; i < N; ++i) {
    if (A[i] == B[0]) {
      cout << B[1] << endl;
    } else {
      cout << B[0] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3200
/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

//#define int long long

using namespace std;
using ll = long long;
using ld = long double;

#define nextline() (std::cerr << "\n")
#define debug(x) (#x " : " + (x))
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabcout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabheadcout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=(n)-1; i >= 0; --i)
#define rrep1(i, n) for(int i=(n); i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
constexpr int INF = 2000000100;
constexpr ll DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> T divup(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
#define divup(a, b) ((a) % (b) == 0 ? (a) / (b) : (a) / (b) + 1)
#define exist_in(list, value) (list.end() != std::find(all(list),value))
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
//template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
//template<class T> T math_C(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
//template<class T> bool compare_by_b(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
//template<class T> T math_gcd(T a, T b) { a = abs(a); b = abs(b); if (a < b) { std::swap(a, b); } T tmp; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; }
//template<class T> T math_lcm(T a, T b) { a = abs(a); b = abs(b); if (a > b) { std::swap(a, b); } if (a == 1) { return b; } T i = a; while (i % b != 0) { i += a; } return i; }
//template<class T1, class T2> bool exist_in(const T1& list, const T2& v) { return (list.end() != std::find(list.begin(), list.end(), v)); }
//template<class T> bool exist_in(const T& c, const typename T::value_type& v) {	return (c.end() != std::find(c.begin(), c.end(), v));}

/*****/

int dight(ll x)
{
	int ret = 0;
	while (x > 0)
	{
		x = x / 10;
		ret++;
	}
	return ret;
}

void Main()
{
	ll N;
	cin >> N;
	int ret = INF;
	for (ll a = 1; a * a <= N; a++)
	{
		if (N % a != 0)	continue;

		ll b = N / a;

		chmin(ret, max(dight(a), dight(b)));
	}

	cout << ret;
}

/*****/

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

	std::cout << std::fixed << std::setprecision(10);


	/*
	while (true)
	{
		Main();
		cout << endl;
	}
	//*/


	Main();

	return 0;
}


Measured memory_bytes: 256
import itertools

dish = []

for i in range(5):
    dish.append(int(input()))

perms = list(itertools.permutations(dish))

res = float('Inf')

for perm in perms:
    x = 0
    for i in range(len(perm)):
        x = x + perm[i]
        if i != len(perm) - 1:
            while x % 10 != 0:
                x = x + 1
    if x < res:
        res = x
        x = 0

print(res)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
    int n,cnt=0,ans=0;
    cin >> n;
    for(int i=1;i<=n;i+=2){
        for(int j=2;j<i;j++){
            if(i%j==0)  cnt++;
        }
        if(cnt==6)  ans++;
        cnt=0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    ll a;
    string s;
    cin>>a>>s;
    ll b=0;
    ll x=100;
    rep(i,4){
        if(i==1) continue;
        b+=x*(s[i]-'0');
        x/=10;
    }
    //cout<<b<<endl;
    ll ans=a*b;
    cout<<ans/100<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define bit(n) 1 << n
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pair <int, int> > vii;
typedef map <int, int> mii;
 
const int Inf = 1000000007;
//const int mod = 998244353;//1000000007;
const double Pi = acos(-1);
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n, c = 0, k, d, t;
set <int> S;

void Solve()
{	
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
	{
		S.insert(i);
	}
	for(int i = 1; i <= k; i++)
	{
		cin >> d;
		for(int j = 1; j <= d; j++)
		{
			cin >> t;
			S.erase(t);
		}
	}
	cout << S.size();
}
 
int main()
{
	Fastio();
	Solve();
}

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

int main() {
  int n;
  cin >> n;
  rep(i,n+1) {
    int rest = n-i*100;
    if (0 <= rest && rest <= 5*i) {
      puts("1");
      return 0;
    }
    if (rest < 0) break;
  }
  puts("0");
  return 0;
}



Measured memory_bytes: 3616
s = input()
if s == s[::-1]:
    flag = True
else:
    flag = False
N = len(s)
if flag:
    new = s[0:int((N-1)/2)]
    if new == new[::-1]:
        flag = True
    else: flag = False

if flag:
    new = s[int((N+2)/2):N]
    if new == new[::-1]:
        flag = True
    else:
        flag = False

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
X = int(input())
X2 = int(str(X)[-2:])

num = 0
for i in range(5, 0, -1):
    q, X2 = divmod(X2, i)
    if q == 0: continue
    num += q
    if X2 == 0: break
    
if X >= num*100: print(1)
else: print(0)  
    


Measured memory_bytes: 38704
while True:
    n = int(raw_input())
    if n == 0:
        break
    a = [0] * n
    dp = [0] * n
    for i in range(n):
        a[i] = int(raw_input())
        if i == 0:
            dp[0] = a[0]
        else:
            dp[i] = max(dp[i-1]+a[i], a[i])
    print max(dp)

Measured memory_bytes: 4472
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;

vector<pair<long long, long long> > a;

int main(){
    long long h, w, d;
    cin >> h >> w >> d;
    a.resize(h * w + 1);
    for(int i = 1; i <= h; ++i)
        for(int j = 1; j <= w; ++j){
            long long c;
            cin >> c;
            a[c] = make_pair(i, j);
        }
    vector<long long> ans(h * w + 1);
    for(int i = 1; i <= h * w; ++i){
        if(i - d <= 0) continue;
        ans[i] = abs(a[i - d].first - a[i].first) + abs(a[i - d].second - a[i].second) + ans[i - d];
    }
    long long t, l, r;
    cin >> t;
    for(int i = 0; i < t; ++i){
        cin >> l >> r;
        cout << ans[r] - ans[l] << endl;
    }
    
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n;

int main()
{
    scanf("%d",&n);
    for (int i=1;i<=9;++i)
    {
        if (n%i==0 && n/i<=9)
        {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 256
import numpy as np


MOD = 10**9 + 7

X, Y = map(int, input().split())

if (X + Y) % 3 != 0:
    print(0)

else:
    if (Y < X/2) or (Y > 2*X):
        print(0)
    
    else:
      
        h = (2 * X - Y) // 3
        v = (2 * Y - X) // 3

        def extgcd(a, b):
            if b == 0:
                x = 1
                y = 0
            else:
                y, x = extgcd(b, a%b)
                y -= a//b * x
            return x, y

        def low_inverse(a):
            ret, _ = extgcd(a, MOD)
            return ret

        def low_combination(m, n):
            # calculate (m+n)!/n!m!
            ret = 1
            numerator = m + n
            for i in range(min(m, n)):
                inv_i = low_inverse(i + 1)
                ret = ret * (numerator - i) * inv_i % MOD
            return ret

        print(low_combination(h, v))


Measured memory_bytes: 12844
import sys
from collections import defaultdict

def main():
    input = sys.stdin.readline
    S = str(input().strip())
    T = str(input().strip())

    if not set(T) <= set(S):
        return -1

    n = len(S)
    d = defaultdict(list)
    for i, s in enumerate(S, start=1):
        d[s].append(i)

    cnt = 0
    pos = 0
    for t in T:
        if pos >= d[t][-1]:
            cnt += 1
            pos = d[t][0]
        else:
            left = 0
            right = len(d[t])
            while left < right:
                mid = (left + right) // 2
                np = d[t][mid]
                if np <= pos:
                    left = mid + 1
                else:
                    right = mid
            pos = d[t][left]

    return n * cnt + pos


if __name__ == '__main__':
    print(main())


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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

bool chkmax(int &x,int y){return x<y?x=y,true:false;}
bool chkmin(int &x,int y){return x>y?x=y,true:false;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

ll x,y;

int main(){
	x=readint(); y=readint();
	if(x<=0&&y>=0) printf("Zero\n");
	else if(x<0&&((y-x+1)&1)) printf("Negative\n");
	else printf("Positive\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    string s;
    while (cin >> s && s != "0"){
        int n = s.length();
        VVI dp(n+1, VI(11));
        REP(i,n){
            int x = s[i] - '0';
            REP(j,11){
                dp[i+1][(10*j+x) % 11] += dp[i][j];
            }
            if (x > 0) dp[i+1][x]++;
        }
        int ans = 0;
        REP(i,n) ans += dp[i+1][0];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 9828
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.nextLine();
		int sum = 0;
		for(int i = 1; i < S.length(); i++) {
			if(S.substring(i - 1, i).equals(S.substring(i, i + 1))) {
				
			} else {
				sum++;
			}
		}
		
		System.out.println(sum);
		
		scan.close();
	}

}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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() {
  string S; cin >> S;
  int N = S.size();
  string a = S.substr(0, (N - 1) / 2);
  string b = S.substr((N + 3) / 2 - 1, (N - 1) / 2);
  
  bool flag = false;
  for(int i = 0; i < (a.size()) / 2; ++i) {
    // cout << a[i] << " " << a[a.size() - i - 1] << endl;
    if(a[i] != a[a.size() - i - 1]) {
      flag = true;
    }
  }
  // cout << a << " " << flag << " " << b << " " << endl;

  for(int i = 0; i < (b.size()) / 2; ++i) {
    // cout << b[i] << " " << b[b.size() - i - 1] << endl;
    if(b[i] != b[b.size() - i - 1]) {
      flag = true;
    }
  }
  // cout << a << " " << flag << " " << b << " " << endl;

  for(int i = 0; i < a.size(); ++i) {
    if(a[i] != b[b.size() - i - 1]) {
      flag = true;
    }
  }

  // cout << a << " " << flag << " " << b << " " << endl;
  if(flag == true) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

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

using namespace std;

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

	double x;
	string u;
	double total=0;
	for (int i = 0; i < n; i++) {

		cin >> x >> u;
		if (u == "JPY") {
			total += x;
		}
		else {
			total += 380000 * x;
		}
	}

	cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

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

    int n, a, b;

    cin >> n >> a >> b;

    cout << min(a, b) << " " << max(0, a + b - n) << endl;

    return 0;
}


Measured memory_bytes: 256
a,b,c,d = map(int, input().split())
i = 0
while True:
    if i % 2 == 0:
        c -= b
    else:
        a -= d
    i += 1
    if a <= 0:
        print("No")
        break
    elif c <= 0:
        print("Yes")
        break


Measured memory_bytes: 9164
#include <iostream>

using namespace std;

int main()
{
    long long n, m;
    cin >> n >> m;
    long long res;
    if(n==1 && m==1){
        res=1;
    } else if(n==1){
        res=m-2;
    } else if(m==1){
        res=n-2;
    } else{
        res=m*n-(m-1+n-1)*2;
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>
#include <iomanip>

using namespace std;
#define REP(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

#define MOD (1'000'000'000+7)

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

bool sorted(vector<int> &v) {
    REP(i, 1, v.size()) {
        if (v[i] < v[i-1]) {
            return false;
        }
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N+1), B(N);
    ll M = 0;
    REP(i, 0, N+1) {
        cin >> A[i];
    }
    REP(i, 0, N) {
        cin >> B[i];
    }
    
    int C = min(A[0], B[0]);
    A[0] -= C;
    M += C;
    B[0] -= C;
    REP(i, 0, N) {
        C = min(A[i], B[i]);
        A[i] -= C;
        M += C;
        B[i] -= C;
        
        C = min(A[i+1], B[i]);
        A[i+1] -= C;
        M += C;
        B[i] -= C;
    }
    cout << M << endl;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

# スペース区切りの整数の入力
list_num = [num for num in input().split()]

# 計算
list_name = []
for str in list_num :
    s = str[0:1]
    list_name.append(s)

# 出力
print("".join(list_name))

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	int n,m;
	int ans=0;
	
	cin>>n>>m;
	ans=(n-1)*(m-1);
	cout<<ans<<endl;
	return 0;
}

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

//

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

int p[100001];
int ind[100001];

#define N 100001

int par[N];
int rnk[N];

void init_uf(){
  REP(i,N){
    par[i]=i;
    rnk[i]=0;
  }
}

int find(int x){
  if(par[x] == x)
    return x;
  else
    return find(par[x]);
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)
    return;
      
  if(rnk[x] < rnk[y])
    par[x] = y;
  else{
    par[y] = x;
    if(rnk[x]==rnk[y]) rnk[x]++;
  }
}

bool same(int x,int y){
  return find(x) == find(y);
}

int main(){
  int n,m;
  cin>>n>>m;
  REP(i,n){
    cin>>p[i+1];
    ind[p[i+1]]=i+1;
  }

  init_uf();
  int dum1,dum2;
  REP(i,m){
    cin>>dum1>>dum2;
    unite(ind[dum1],ind[dum2]);
  }

  int ret = 0;
  REP(i,n){
    if(same(i+1,ind[i+1])) ret++;
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        int xor = 0;
        for(int i=0;i<N;i++){
            a[i] = sc.nextInt();
            xor ^= a[i];
        }
        if(xor == 0){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }


    }



}


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

int main(){
    int N;cin>>N;
    vector<int> H(N);
    rep(i,0,N) cin>>H.at(i);
    int c=0;
    int max=0;
    int j=N-1;
    while(j>max&&j!=0){
        rep(i,N-(j+1),N-1) 
        if(H.at(i)>=H.at(i+1)) c++;
        else {
            j--;
            break;
        }
        if(c>=max) max=c;
        c=0;
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 640