akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> a(n);
    REP(i,n)cin >> a[i],--a[i];
    int32 cnt = 0;
    int32 cur = 0;
    vector<bool> visited(n,false);
    visited[0] = true;
    REP(i,n){
        ++cnt;
        cur = a[cur];
        if(visited[cur]){
            ANS(-1);
            return 0;
        }
        if(cur == 1){
            ANS(cnt);
            return 0;
        }
        visited[cur] = true;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
 
  int W,H,w,h;
 
  while (1) {
    scanf("%d %d",&W,&H);
 
    if (H == 0 && W == 0)
      break;

    for (w = 1;w <= W;w++){
      if (1 == w || w == W){
	for (h = 1;h <= H;h++){
	  putchar('#');
	}
      } else {
	for (h = 1;h <= H;h++){
	  if(1 == h || h == H){
	    putchar('#');
	  } else {
	    putchar('.');
	  }
	}
      }
      putchar('\n');
    }
    printf("\n");
  }
  return 0;
}
	

Measured memory_bytes: 576
// ITP1_10 ­ D Distance II
// 2018.4.2

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double dist_1 (int, int*, int*);
double dist_2 (int, int*, int*);
double dist_3 (int, int*, int*);
double dist_chev (int, int*, int*);

int
main ()
{
  int n = 0;
  int x[1000] = {};
  int y[1000] = {};
  int i;
  double d1, d2, d3, dchev;
    
  scanf ("%d\n", &n);
  for (i = 0; i < n - 1; i++)
    {
      scanf ("%d ", &x[i]);
    }
  scanf ("%d\n", &x[n - 1]);

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

  printf ("%f\n", d1 = dist_1 (n, x, y));
  printf ("%f\n", d2 = dist_2 (n, x, y));
  printf ("%f\n", d3 = dist_3 (n, x, y));
  printf ("%f\n", dchev = dist_chev (n, x, y));

  return 0;
}

double dist_1 (int N, int *X, int *Y)
{
  double Z = 0;
  int i;
  for ( i = 0; i < N; i++)
    {
      Z += (double)(abs(X[i] - Y[i]));
    }
  return Z;
}

double dist_2 (int N, int *X, int *Y)
{
  double Z, Z2;
  Z = Z2 = 0;
  int i;
  for ( i = 0; i < N; i++)
    {
      Z2 += (double)(abs(X[i] - Y[i]) * abs(X[i] - Y[i]));
    }

  Z = sqrt(Z2);
  return Z;
}

double dist_3 (int N, int *X, int *Y)
{
  double Z, Z3;
  Z = Z3 = 0;
  int i;
  for ( i = 0; i < N; i++)
    {
      Z3 += (double)(abs(X[i] - Y[i]) * abs(X[i] - Y[i]) * abs(X[i] - Y[i]));
    }

  Z = cbrt(Z3);
  return Z;
}

double dist_chev (int N, int *X, int *Y)
{
  double chev;
  chev = 0;
  int i;
  for ( i = 0; i < N; i++)
    {
      if(chev <= (double)(abs(X[i] - Y[i])))
	 {
	   chev = (double)(abs(X[i] - Y[i]));
	 }
    }
  return chev;
}



Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
 
using namespace std;
typedef long long ll;

ll ans,mx,mn=1e10,sum;
int main(){
	string s;
	cin>>s;
	for(int i=0; i<s.size(); i++){
		if(s[i] == '1') ans++;
		else mx++;
	}
	cout<<2*min(mx,ans);
}

Measured memory_bytes: 512
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		long X = sc.nextLong();
		
		sc.close();

		long ans = 100;
		int y = 1;
		for(;;y++) {
			ans *= 1.01;
			
			if(ans >= X) {
				break;
			}
		}
		out.println(y);
		
	}

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

	@SuppressWarnings("unused")
	private String join(String delimiter, int[] a) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < a.length; i++) {
			sb.append(a[i]);
			sb.append(delimiter);
		}
		return sb.substring(0, Math.max(sb.length() - delimiter.length(), 0));
	}

	@SuppressWarnings("unused")
	private String join(String delimiter, long[] a) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < a.length; i++) {
			sb.append(a[i]);
			sb.append(delimiter);
		}
		return sb.substring(0, Math.max(sb.length() - delimiter.length(), 0));
	}

	@SuppressWarnings("unused")
	private int max(int[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		int candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate > arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private long max(long[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		long candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate > arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private int min(int[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		int candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate < arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private long min(long[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		long candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate < arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}

	@SuppressWarnings("unused")
	private long[] nextLongArray(Scanner sc, int n) {
		long[] result = new long[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextLong();
		}
		return result;
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray1origin(Scanner sc, int n) {
		int[] result = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


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

using namespace std;
typedef long long int ll;
int main() 
{

ll n,m;
cin>>n>>m;
ll i=1;ll sum=0;
while(i<=m)
{
    ll x;
    cin>>x;
    sum=sum+x;
i++;    
}
ll ans=n-sum;
if(ans<0)
{
    cout<<"-1";
}
else
{
    cout<<ans;
}

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	map <char,int> ct;
	int mx=0;
	for (const char ch :s)
		ct[ch]++,mx=max(mx,ct[ch]);
	cout<<(ct.size()==2&&mx==2?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN,"%d",$N);
$arr = explode(" ",rtrim(fgets(STDIN)));
$res = 0;
// ０が配列の中に入っていなかったら計算する
if(!array_search(0, $arr)){
    $res = 1;
    for($i=0; $i<$N; $i++){
        $res = $res * $arr[$i];
    }
    if($res > pow(10,18)){
        $res = -1;
    }
};
echo $res;
?>

Measured memory_bytes: 25488
#include "bits/stdc++.h"
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const long long mod = 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;
}

ll powMod(ll n, ll k, ll m) {
	if (k == 0) {
		return 1;
	} else if (k % 2 == 1) {
		return powMod(n, k - 1, m) * n % m;
	} else {
		ll t = powMod(n, k / 2, m);
		return t * t % m;
	}
}

int main() {
	int k, a, b;
	cin >> k >> a >> b;

	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}

	cout << "NG" << endl;
}


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

ll mod = 1e9 + 7;

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<int>> A(H, vector<int>(W, 0)), B(H, vector<int>(W, 0)); 
    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++) {
        for (int j = 0; j < W; j++) {
            cin >> B[i][j];
        }
    }
    vector<vector<vector<bool>>> dp(H, vector<vector<bool>>(W, vector<bool>(7000, false)));
    dp[0][0][abs(A[0][0]-B[0][0])] = true;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int t = abs(A[i][j]-B[i][j]);
            for (int k = 0; k < 7000; k++) {
                if (i > 0) {
                    if (dp[i-1][j][abs(k-t)]) dp[i][j][k] = true;
                    if (k+t < 7000 && dp[i-1][j][k+t]) dp[i][j][k] = true;
                }
                if (j > 0) {
                    if (dp[i][j-1][abs(k-t)]) dp[i][j][k] = true;
                    if (k+t < 7000 && dp[i][j-1][k+t]) dp[i][j][k] = true;
                }
            }
        }
    }
    int ans = 81;
    for (int i = 0; i <= 80; i++) {
        if (dp[H-1][W-1][i]) ans = min(ans, i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define chmin(x, y) x = min(x, y)
using ll = long long;
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

const int MAX = 2000005;
const long long MOD = 1000000007;

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;
}

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;
}
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;
}

const int INF = 1001001001;
int dp[1000005][2];
int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  s += '0';
  int n = s.size();
  rep(i, n+1) rep(j, 2) dp[i][j] = INF;
  dp[0][0] = 0;
  rep(i, n) rep(j, 2) {
    int x = s[i] - '0';
    x += j;
    if(x < 10) chmin(dp[i+1][0], dp[i][j]+x);
    if(x > 0) chmin(dp[i+1][1], dp[i][j]+(10-x));
  }
  int ans = dp[n][0];
  cout << ans << endl;
  return 0;
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

ll lcm(ll x, ll y) {
    if (x > y) swap(x, y);
    if (x % y == 0) return x;
    ll v = gcd(x, y);
    return (x/v)*y;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n; std::cin >> n;
    vl t(n); rep(i, n) std::cin >> t[i];
    ll ans = t[0];
    rrep(i, n-1) {
        ans = lcm(ans, t[i]);
    }
    std::cout << ans << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){

	char s[200000];
	scanf("%s",s);
	int fin;
	fin = strlen(s);

	int b,e;
	int i;
	for(i=0; i<fin; i++){
		if(s[i]=='A'){
			b =i;
			break;
		}
	}

	for(i=fin-1; i>=0; i--){
		if(s[i]=='Z'){
			e = i;
			break;
		}
	}
	printf("%d\n", e-b+1);

return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007

using namespace std;

signed main(){
  int n;
  cin>>n;
  int ans=0;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin>>a[i];
  }
  int sum = a[0];
  for(int i =1; i < n; i++){
    ans = (ans + ((sum * a[i]) % MOD)) % MOD;
    sum = (sum + a[i]) % MOD; 
  }
  cout << ans <<endl;
}

Measured memory_bytes: 4744
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, Q = map(int, readline().split())

PATH = [[] for _ in range(N + 1)]

for _ in range(N-1):
    a, b = map(int, readline().split())
    PATH[a].append(b)
    PATH[b].append(a)

POINT = [0] * (N + 1)

for _ in range(Q):
    p, x = map(int, readline().split())
    POINT[p] += x


ans = [0] * (N+1)

STATE = [False] * (N+1)


def dfs(s, plus):
    p = POINT[s]
    pt = p + plus
    ans[s] += pt

    STATE[s] = True

    for v in PATH[s]:
        if STATE[v]:
            continue
        dfs(v, pt)


dfs(1, 0)
print(" ".join(map(str, ans[1:])))


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

int main()
{
	ios_base::sync_with_stdio(false);	
	cin.tie(NULL);
	string s="";
	cin>>s;
	int flag=0;
	for(int i=0;i<s.length();++i)
	{
		if(s[i]=='7')
		{
		flag=1;
		break;
		}
	}
	if(flag==1)
	cout<<"Yes\n";
	else
	cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin>>s;
  sort(s.begin(), s.end());
  cout<<(s=="abc"?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
#define debug(x) cerr << x << "=" << x << endl;
#define lgr cerr << "----------" << endl;

int main() {
    string s;
    while(cin >> s) {
        int l = 0, r = s.size()-1, ans = 0;
        int flag = 1;
        while(l <= r) {
            //debug(l); debug(r);
            if(s[l] == s[r]){
                l++;
                r--;
            }
            else if(s[l] == 'x') {
                ans++;
                l++;
            }
            else if(s[r] == 'x') {
                ans++;
                r--;
            }
            else {
                cout << "-1" << endl;
                flag = 0;
                break;
            }
        }
        if(flag) cout << ans << endl;
        //lgr;
    }
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector <int> A(N);
  
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  
  int count =0;
  int S = 1;
 for(int i=0;i<N;i++){

   S = A.at(S-1);
    count ++;
     if(S==2){
       cout << count << endl;
       break;
     }else if(i == N-1){ 
       cout << -1 << endl;
     }
   }
}


Measured memory_bytes: 640
#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>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

void solve() {
    string s;
    cin >> s;

    int mod = 0;
    for (int i = 0; i < s.size(); ++i) {
        mod += s[i] - '0';
        mod %= 9;
    }

    cout << (mod == 0 ? "Yes" : "No") << endl;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 3360
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int n,m;
    ll x1,x2,X=0,y1,y2,Y=0;
    cin>>n>>m;
    //x
    cin>>x1;
    rep(i,n-1){
        cin>>x2;
        X=(X+(x2-x1)*(i+1)*(n-i-1))%mod;
        x1=x2;
    }
    //y
    cin>>y1;
    rep(i,m-1){
        cin>>y2;
        Y=(Y+(y2-y1)*(i+1)*(m-i-1))%mod;
        y1=y2;
    }
    cout<<(X*Y)%mod<<endl;
    return 0;
}

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

using namespace std;

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


Measured memory_bytes: 13760
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    using namespace std;
    #define INF 10000000;
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
 
  
  
    int main(){
      string s,t;
      cin >>s>>t;
      string res = t+s;
      cout << res <<endl;
      
    }
      

Measured memory_bytes: 256
module Main where

import Control.Applicative
import Control.Monad
import Data.List (unfoldr)

func :: Int -> Int -> Int
func d n = sum $ unfoldr f n
    where
    f 0 = Nothing
    f x = Just (r, q)
        where
        (q, r) = x `divMod` d

main :: IO ()
main = do
    n <- readLn :: IO Int
    let as = [x | i <- [0..n], let x = func 6 i + func 9 (n - i)]
    print $ minimum as

Measured memory_bytes: 892
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1)
    {
        cerr << name << " = " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args)
    {
        const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
        __f(comma+1, args...);
    }
#else
#define debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;  // Min Heap

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 1e5 + 5;
ll n, a, b, ans, h[MAXN];

bool check(ll tot)
{
    if(!tot) return false;
    ll val = 0;
    for(int i=0;i<n;i++)
    {
        if(h[i] <= tot * b) continue;

        ll temp = (h[i] - tot * b ) / (a - b);
        
        if( (h[i] - tot * b ) % (a - b) )
            temp++;    

        val += temp;
    }

    if(val <= tot) return true;
    return false;
}

ll bs(ll start, ll end)
{
    ll mid = (start + end) / 2;
    bool f1 = check(mid);
    bool f2 = check(mid - 1);
    if(f1 && !f2) return mid;
    else if(f2) end = mid - 1;
    else start = mid + 1;
    return bs(start, end);

/*    ll lo=start,hi=end,md,prev=-1;
    while(lo<=hi)
    {
        md=(lo+hi)/2;
        if(prev==md)
            break;
        prev=md;

        if(check(md))
            hi=md;
        else
            lo=md+1;
    }

    return hi;
*/}

int main()
{
    FAST_IO;
    ll x=0;
    cin >> n >> a >> b;
    for(int i=0;i<n;i++)
    {
        cin >> h[i];
        x+=h[i]/a;
        if(h[i]%a)
            x++;
    }
    cout << bs(1, x) << endl;
    return 0;
}

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

int main(){
	int i,j,n,num;
	char m;
	int a[4][13]={0};
	
	cin>>n;
	for(i=0;i<n;i++){
		cin>>m>>num;
		if(m=='S')
			a[0][num-1]=1;
		if(m=='H')
			a[1][num-1]=1;
		if(m=='C')
			a[2][num-1]=1;
		if(m=='D')
			a[3][num-1]=1;
	}
	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
			if(a[i][j]==0 && i==0)
				cout<<"S"<<" "<<j+1<<endl;
			if(a[i][j]==0 && i==1)
				cout<<"H"<<" "<<j+1<<endl;
		        if(a[i][j]==0 && i==2)
				cout<<"C"<<" "<<j+1<<endl;	
			if(a[i][j]==0 && i==3)
				cout<<"D"<<" "<<j+1<<endl;
		}
	}
											
}
		
		
	

Measured memory_bytes: 1160
#include<cstdio>
#include<math.h>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define Case int t;scanf("%d", &t);while(t--)
typedef long long ll;
const int Max = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
int n, m;
int dp[Max];
int in[Max];
vector<int> G[Max];
queue<int> que;
int main(){
	cin >> n >> m;
	int u, v;
	for(int i = 0; i < m; i++){
		cin >> u >> v;
		G[u].push_back(v);
		in[v]++;
	}

	for(int i = 1; i <= n; i++){
		if(!in[i]) que.push(i);
	}

	int ans = 0;
	while(!que.empty()){
		int now = que.front();
		que.pop();
		for(int i = 0; i < G[now].size(); i++){
			dp[G[now][i]] = max(dp[G[now][i]], dp[now]+1);
			ans = max(ans, dp[G[now][i]]);
			in[G[now][i]]--;
			if(!in[G[now][i]]) que.push(G[now][i]);
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 9820
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N;int M;cin>>N>>M;
    int sum=0;
    rep(i,M){
        int a;
        cin>>a;
        sum+=a;
    }
    if(N>=sum){
        cout<<N-sum<<endl;
    }else{
        cout<<-1<<endl;
    }
}

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

using namespace std;
const int maxn =  1e6 + 10;
#define ll long long
#define ios std::ios::sync_with_stdio(false)
const ll INF(0x3f3f3f3f3f3f3f3fll);
const int inf(0x3f3f3f3f);
/*


ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll pow_mod(ll x,ll n,ll mod){ll res=1;while(n){if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}//xµÄn´Î·½mod


ll mult(ll a,ll b,ll p){a%=p;b%=p;ll r=0,v=a;while(b){if(b&1){r+=v;if(r>p)r-=p;}v<<=1;if(v>p)v-=p;b>>=1;}return r;}
ll quick_pow(ll a,ll b,ll p){ll r=1,v=a%p;while(b){if(b&1)r=mult(r,v,p);v=mult(v,v,p);b>>=1;}return r;}
bool CH(ll a,ll n,ll x,ll t)
{ll r=quick_pow(a,x,n);ll z=r;for(ll i=1;i<=t;i++){r=mult(r,r,n);if(r==1&&z!=1&&z!=n-1)return true;z=r;}return r!=1;}
bool Miller_Rabin(ll n)
{if(n<2)return false;if(n==2)return true;if(!(n&1))return false;ll x=n-1,t=0;while(!(x&1)){x>>=1;t++;}srand(time(NULL));
ll o=8;for(ll i=0;i<o;i++){ll a=rand()%(n-1)+1;if(CH(a,n,x,t))return false;}return true;}


*/

#define int long long
#define sc(t) scanf("%lld",&t)
#define pr(ans) printf("%lld\n",ans)
ll pow_mod(ll x,ll n,ll mod){ll res=1;while(n){if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}//xµÄn´Î·½mod
template<typename T>void read(T &res){bool flag=false;char ch;while(!isdigit(ch=getchar()))(ch=='-')&&(flag=true);
for(res=ch-48;isdigit(ch=getchar());res=(res<<1)+(res<<3)+ch - 48);flag&&(res=-res);}
typedef unsigned long long ULL;
const double pi = 3.1415926535897932384626;
int gcd(int a,int b){return !b?a:gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
#define debug(x) cout << #x << " : " << x << '\n';
#define sb cout << "sb\n";
#define fi first
#define se second
#define pb(a) push_back(a)
#define cn cout << '\n'
#define mp(a , b) make_pair(a , b)
const int mod = 8011200280112002;

signed main()
{
    ios;///60 10 50
    cin.tie(0);
    //cout << 973303 + 519683 << ' ' << 2 * 866255 << '\n';
    int a , b;
    cin >> a >> b;
    cout << a * b << '\n';
    
	return 0;
}


Measured memory_bytes: 3652
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
c = defaultdict(int)
for x in a:
  c[x] += 1

sq = False
top, sec = 0,0
for k,v in c.items():
    if v < 2:
        continue
    if k > top:
        sq = v >= 4
        sec = top
        top = k
    elif k > sec:
        sec = k

if sq:
    print(top * top)
else:
    print(top * sec)

Measured memory_bytes: 18600
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int func(int d, int n){
  int tmp = 0;
  int count1 = 0;
  int count2 = 0;
  int res = 1;
  
  while(true){
    count1 = 0; //初期化
    tmp = res;
    while(tmp%100 == 0){ //tmpが100で割り切れたら
      tmp /= 100;
      count1++; //count1を増やす
    }
    
    //割り切れなくなったところで
    if(count1 == d)count2++; //もし割り切れた回数がdと等しければcount2を増やす
    if(count2 == n) return res; //dと同じだった回数が等しくなったnを返す
    
    res++; //でなければ次へ
  }    
}

int main(){
  int d,n;
  cin >> d >> n;
  
  int ans = func(d,n);
  
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
h.append(1001001001)
can = True
for i in range(n, 0, -1):
    if h[i - 1] - h[i] > 1:
        can = False
        break
    if h[i - 1] - h[i] == 1:
        h[i - 1] -= 1
if can:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 63856
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+5;
int a[maxn];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int sum = 0;
	for (int i = 1; i <=m; ++i)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
		/* code */
	}
	if(sum>n) printf("-1");
	else printf("%d", n-sum );
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

bool exist[2001];

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    vi a(N);
    rep(i,N) cin>>a[i];
    rep(S,1<<N){
        int sum=0;
        rep(i,N)if(S>>i&1) sum+=a[i];
        if (sum>2000) continue;
        exist[sum]=true;
    }

    int Q; cin>>Q;
    while(Q--){
        int M; cin>>M;
        if (exist[M]) cout<<"yes\n";
        else cout<<"no\n";
    }
    return 0;
}



Measured memory_bytes: 3136
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

map<long long,long long>s;
long long a[100005];
map<long long,long long>vis;

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%lld",&a[i]);
		s[a[i]]++;
	}
	sort(a + 1,a + 1 + n);
	long long l = 0,r = 0;
	for(int i = n;i >= 1;i--){
		if(vis[a[i]] == 0 && (l == 0 || r == 0)){
			vis[a[i]] = 1;
			if(s[a[i]] == 2 || s[a[i]] == 3){
				if(l == 0){
					l = a[i];
					continue;
				}
				if(r == 0){
					r = a[i];
					continue;
				}
			}
			else if(s[a[i]] >= 4){
				if(l == 0 && r == 0){
					l = a[i];
					r = a[i];
					break;
				}
				if(l == 0) l = a[i];
				if(r == 0) r = a[i];
			}
		}
	}
	printf("%lld",l*r);
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
int main(){
    int n,m,cnt=1,a;
    cin>>n;
    cin>>m;
    REP(i,n-1){
        cin>>a;
        if(m>=a){
            cnt++;
            m=a;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<cstdio>

bool solve(){
	int n,m,a[100],b[100],sum_a = 0,sum_b = 0;
	scanf("%d %d",&n,&m);
	if(n==0&&m==0) return false;
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
		sum_a += a[i];
	}
	for(int i=0;i<m;i++){
		scanf("%d",b+i);
		sum_b += b[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(sum_a-a[i]+b[j]==sum_b-b[j]+a[i]){
				printf("%d %d\n",a[i],b[j]);
				return true;
			}
		}
	}
	printf("-1\n");
	return true;
}

int main(){
	while(solve()){}
}

Measured memory_bytes: 2620
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
using namespace std;

int main(){
	long long h, w;
	cin >> h >> w;

	if ((w == 1) || h==1){
		cout << 1 << endl;
		return 0;
	}

	if (h*w%2==0){
		cout << h*w/2 << endl;
	}
	else{
		cout << h*w/2+1 << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

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

    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        A[i] -= i + 1;
    }
    sort(A.begin(), A.end());

    ll b = A[N / 2];
    if(N % 2 == 0){
        b = (b + A[N / 2 - 1]) / 2;
    }
    ll ans = 0;
    for(ll v : A){
        ans += abs(v - b);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<char>s(10);
  for (int i = 0; i < s.size(); i++) cin >> s.at(i);
  
  if ( s.at(3) == '7') s.at(3) = '8';
  
  for ( int i = 0; i < s.size(); i++) cout << s.at(i);
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
#define N 505
#define Abs(x) ((x) > 0 ? (x) : -(x))
#define Min(x,y) ((x) < (y) ? (x) : (y))
#define Max(x,y) ((x) > (y) ? (x) : (y))
inline ll read(){
	ll 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;
}

char a[N][N],b[N][N];
int n,m;

int main(){
	n = read(); m = read();
	for(int i = 1;i <= n;i++){
		scanf("%s",a[i]+1);
		for(int j = 1;j <= m;j++)
			b[i][j] = a[i][j];
	}
	// puts("1");
	for(int i = 1;i <= n;i++){
		if(i&1){
			for(int j = 1;j < m;j++)
				a[i][j] = '#';
			b[i][m] = '#';
		}
		else{
			for(int j = 2;j <= m;j++)
				b[i][j] = '#';
			a[i][1] = '#';
		}
	}
	for(int i = 1;i <= n;i++)
		printf("%s\n",a[i]+1);
	puts("");
	for(int i = 1;i <= n;i++)
		printf("%s\n",b[i]+1);
	puts("");
	return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 100000000000000000
#define MOD 1000000007


typedef long long ll;
typedef pair<ll,pair<ll,ll> > P;

ll d[111][111];

int main()
{
	int n,m,l;
	while(cin >> n >> m >> l,n|m|l){
		vector<vector<P> > v(n);
		REP(i,111)REP(j,111)d[i][j] = LLINF;
		REP(i,m){
			int a,b,c,d;cin >> a >> b >> c >> d;
			a--;b--;
			v[a].PB(MP(b,MP(c,d)));
			v[b].PB(MP(a,MP(c,d)));
		}
		
		d[0][l] = 0;
		priority_queue<P,vector<P>,greater<P> > pq;
		pq.push(MP(0,MP(0,l)));
		while(!pq.empty()){
			P now = pq.top();pq.pop();
			int node = now.SE.FI;
			int kinnka = now.SE.SE;
			int teki = now.FI;
			if(teki > d[node][kinnka])continue;
			REP(i,v[node].size()){
				int aite = v[node][i].FI;
				int kyori = v[node][i].SE.FI;
				int plus = v[node][i].SE.SE;
				
				if(kinnka >= kyori){
					if(d[aite][kinnka-kyori] > teki){
						d[aite][kinnka-kyori] = teki;
						pq.push(MP(teki,MP(aite,kinnka-kyori)));
					}
				}
				if(d[aite][kinnka] > teki + plus){
					d[aite][kinnka] = teki + plus;
					pq.push(MP(teki + plus,MP(aite,kinnka)));
				}
			}
		}
		ll ans = LLINF;
		REP(i,l+1)ans = min(ans,d[n-1][i]);
		DBG(cout << "ANS IS ";);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 4464
#include<bits/stdc++.h>
using namespace std;
vector<int >v;
int main()
{
    int t,n,c,x,m,s=0;
    double p;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        s+=x;
        v.push_back(x);
    }
    sort(v.begin(),v.end(),greater<int>() );
    p=(double)s/(4.0*m);
    for(int i=0;i<m;i++)
    {
        if(v[i]<p)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";

}


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

# 奇数の数を数える
odd_cnt = 0
for a in A:
    if a % 2 != 0:
        odd_cnt += 1

# 全てのが偶数の時
if odd_cnt == 0:
    if P == 0:
        print(2**N)
    else:
        print(0)
    exit(0)

print(2**(N-1))


Measured memory_bytes: 9184
#include <iostream>
#include <vector>

using namespace std;

class Record {
    public:
        int t, n, m, s;
};

int compute_time(int s, int e, vector<Record> records) {
    int count = 0;
    int time = 0;
    int table[1261];
    for (int i=0; i<=1260; i++) {
        table[i] = 0;
    }
    for (int i=0; i<(int)records.size(); i++) {
        table[records[i].t] += 2*records[i].s-1;
    }
    for (int i=0; i<=1260; i++) {
        count += table[i];
        if (count > 0 && s <= i && i < e) {
            time++;
        }
    }
    return time;
}

int main() {
    int n, m, r, q;
    while (true) {
        vector<Record> records[10001];
        cin >> n >> m;
        if (n == 0) {
            return 0;
        }
        for (int i=0; i<=10000; i++) {
            records[i].clear();
        }
        cin >> r;
        for (int i=0; i<r; i++) {
            Record rec;
            cin >> rec.t >> rec.n >> rec.m >> rec.s;
            records[rec.m].push_back(rec);
        }
        cin >> q;
        for (int i=0; i<q; i++) {
            int s, e, m;
            cin >> s >> e >> m;
            cout << compute_time(s, e, records[m]) << endl;
        }
    }
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  string s;
  cin >> s;
  string t;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B' && s[i + 1] == 'C') {
      t += "X";
      i++;
    } else if (s[i] == 'A') {
      t += "A";
    } else {
      t += "C";
    }
  }
  ll ans = 0, count = 0;
  for (int i = t.size() - 1; i >= 0; i--) {
    if (t[i] == 'C') count = 0;
    if (t[i] == 'X') count++;
    if (t[i] == 'A') ans += count;
  }
  cout << ans << endl;
}


Measured memory_bytes: 776
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
x = input()
b = []
c = [0, 1, 1]
for i in range(n+2):
    cnt = 0
    for j in range(101):
        if i >> j & 1:
            cnt += 1
    b.append(cnt)

for i in range(3, n+2):
    c.append(c[i % b[i]]+1)

ans = []
tmp1 = 0
tmp2 = 0
cnt = x.count("1")
if cnt != 1:
    for i in range(n):
        if x[i] == "1":
            tmp1 += pow(2, n-(i+1), cnt+1)
            tmp2 += pow(2, n-(i+1), cnt-1)
    for i in range(n):
        if x[i] == "1":
            ans.append(c[(tmp2 - pow(2, n-(i+1), cnt-1)) % (cnt-1)]+1)
        else:
            ans.append(c[(tmp1 + pow(2, n-(i+1), cnt+1)) % (cnt+1)]+1)

    for i in ans:
        print(i)
else:
    for i in range(n):
        if x[i] == "1":
            tmp1 += pow(2, n-(i+1), cnt+1)
    for i in range(n):
        if x[i] == "1":
            ans.append(0)
        else:
            ans.append(c[(tmp1 + pow(2, n-(i+1), cnt+1)) % (cnt+1)]+1)

    for i in ans:
        print(i)


Measured memory_bytes: 104540
N, M = map(int, input().split())
As = [int(i) for i in input().split()]

all_num = sum(As)

test = []
test = sorted(As)[::-1]

is_true = True
new = []
key = all_num * (1 / (4 * M))
for idx in range(len(test)):

    if test[idx] < key:
        new = test[:idx]
        is_true = False
        break

if is_true:
    len_ans = len(test)

else:
    len_ans = len(new)


if len_ans >= M:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
a = [list(map(int, input().split())) for i in range(3)]
f = [[False]*3 for i in range(3)]
n = int(input())
b = []
for i in range(n):
    b.append(int(input()))
for y in range(3):
    for x in range(3):
        if a[y][x] in b:
            f[y][x] = True
for y in range(3):
    if f[y][0] and f[y][1] and f[y][2]:
        print("Yes")
        exit()
for x in range(3):
    if f[0][x] and f[1][x] and f[2][x]:
        print("Yes")
        exit()
if f[0][0] and f[1][1] and f[2][2]:
    print("Yes")
    exit()
if f[2][0] and f[1][1] and f[0][2]:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 3064
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

s = ns()
for i in range(1,10):
    if s == 'hi'*i:
        print('Yes')
        break
else:
    print('No')


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

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

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> FI(h);
    rep(i, h) cin >> FI[i];

    int ans = 0;
    //スタートとゴールを全探索
    rep(sy, h)
    {
        rep(sx, w)
        {
            if (FI[sy][sx] == '#')
                continue;
            //すべての距離を-1(未探索に)
            vector<vector<int>> dist(h, vector<int>(w, -1));
            // 「一度見た頂点」のうち「まだ訪れていない頂点」を表すキュー
            queue<pair<int, int>> que;
            que.push(make_pair(sy, sx)); // スタートを push
            dist[sy][sx] = 0;
            //探索を実施
            while (!que.empty())
            {
                pair<int, int> current_pos = que.front(); // キューの先頭を見る (C++ ではこれをしても pop しない)
                int y = current_pos.first;
                int x = current_pos.second;
                que.pop(); // キューから pop を忘れずに

                // 隣接頂点を探索
                for (int direction = 0; direction < 4; ++direction)
                {
                    int next_x = x + dx[direction];
                    int next_y = y + dy[direction];
                    if (next_x < 0 || next_x >= w || next_y < 0 || next_y >= h)
                        continue; // 場外アウトならダメ
                    if (FI[next_y][next_x] == '#')
                        continue; // 壁はダメ
                    // まだ見ていない頂点なら push
                    if (dist[next_y][next_x] == -1)
                    {
                        que.push(make_pair(next_y, next_x));
                        dist[next_y][next_x] = dist[y][x] + 1; // (next_x, next_y) の距離も更新
                        ans = max(ans, dist[next_y][next_x]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n,i=0;
  cin >>n;
  while (pow(2,i)<=n) {
    if (pow(2,i+1)>n) {
      cout<<pow(2,i)<<endl;
      break;
    }
    else{
      i+=1;
    }
  }
}



Measured memory_bytes: 512
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=100000007;
const ll INF=1000000000000000001;
int main(){
    ll n;cin>>n;
    ll b[3]={0};
    rep(i,n){
        ll a;cin>>a;
        ll cnt=0;
        while(a%2==0){
         cnt++;
         a/=2;
        }
        if(cnt==0)b[0]++;
        if(cnt==1)b[1]++;
        if(cnt>=2)b[2]++;
    }
    if(b[1]==0){
        if(b[0]-1<=b[2])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
        return 0;
    }
    if(b[1]!=0){
        if(b[0]<=b[2])cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	if(n == 1){
		cout << "Hello World" << endl;
	}else if(n == 2){
		int a,b;
		cin >> a >> b;
		cout << a + b << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define vvi vector<vi >
#define str string
#define vs vector<str>
#define vb vector<bool>
#define slli set<lli>
#define mii map<int, int>
#define mlli map<int, lli>
#define msi map<str, int>
#define mp make_pair
#define pii pair<int, int>
#define pll pair<lli, lli>
#define vpii vector<pii >
#define vpll vector<pll >
#define pb push_back
#define loop(i, s, l, j) for(int i = s; i < l; i += j)
#define rloop(i, s, l, j) for(int i = s; i >= l; i -= j)
#define rep(i, n) loop(i,0,n,1)
#define rrep(i, n) rloop(i,n-1,0,1) 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ft first
#define sd second   
#define mit mii::iterator
#define vit vi::iterator
#define all(a) a.begin(),a.end()
#define min3(a, b, c) min(a, min(b, c))
#define mod 1000000007
#define inf 1000000000
#define limit 200001
/**********************************************************************************************************************************************/
int dx4[4] = {0, -1, 0, 1};
int dy4[4] = {1, 0, -1, 0};
int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Power(int base,int exp){int ans=1;  while(exp > 0){if(exp&1)ans=(1LL*ans*base)%mod; exp=exp>>1; base=(1LL*base*base)%mod;}  return ans;}
/**********************************************************************************************************************************************/ 

void input()
{
    int k;
    cin >> k;

    lli m = 0;
    rep(i,10000001)
    {
        m = (m * 10 + 7) % k;
        if(m == 0)
        {
            cout << i+1 << '\n';
            return;
        }
    }
    cout << -1 << '\n';
}
 
int main()
{
    

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
 
    fastio();
    int q = 1;
    //cin >> q;
    while(q--)
        input();
}

Measured memory_bytes: 3624