akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

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

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

int N;
vector<int> w;

int solve() {
	//初期化
	//操作の対象は隣合う2マス
	//幅1や幅0の隙間は一つもとることができない。
	vector<vector<int>> dp(N + 1, vector<int>(N + 1, -N));
	for (int i = 0; i <= N; i++) {
		dp[i][i] = 0;
		if (i < N)dp[i][i + 1] = 0;
	}

	//幅が小さい方から更新するので、それより短い区間はすべて値が入ってる。
	//[l,r)なので右端の要素はr-1
	for (int bet = 2; bet <= N; bet++) {
		//左端
		for (int i = 0; i + bet <= N; i++) {
			int j = i + bet;

			//i,jの間が全部抜けてる状態ならi,jも抜けるかもしれない
			if (dp[i + 1][j - 1] == j - i - 2 && abs(w[i] - w[j - 1]) <= 1) {
					chmax(dp[i][j], j - i);
					continue;
			}
			
			//i,jの間の区切り方を全部試す
			for (int k = i + 1; k <= j - 1; k++) {
				chmax(dp[i][j], dp[i][k] + dp[k][j]);
			}
			

		}
	}

	return dp[0][N];
}

int main() {
	while (cin >> N,N) {
		w.resize(N);
		for (int i = 0; i < N; i++)cin >> w[i];
		cout << solve() << endl;
	}
	return 0;
}


Measured memory_bytes: 3296
function main(input) {
  var temp = input.split('\n');
  for (var i = 0; i < temp.length; i++) {
    var temp2 = temp[i].split(' ').map(Number);
    var m = temp2[0];
    var f = temp2[1];
    var r = temp2[2];

    if (m == -1 && f == -1 && r == -1) {
      break;
    } else if (m == -1 || f == -1) {
      console.log('F');
    } else if ((m + f) >= 80) {
      console.log('A');
    } else if ((m + f) >= 65) {
      console.log('B');
    } else if ((m + f) >= 50) {
      console.log('C');
    } else if ((m + f) >=30) {
      if (r >= 50) {
        console.log('C');
      } else {
        console.log('D');
      }
    } else {
      console.log('F');
    }
  }
}

var x = require('fs').readFileSync('/dev/stdin', 'utf-8');
main(x);


Measured memory_bytes: 15156
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <map>

int main(void) {

	int a, b;

	std::cin >> a >> b;

	std::cout << (a * b) - (a + b) + 1 << std::endl;

	return 0;
}

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  cout << N * N * N << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
int main(void)
{
	int n,y,i,j,k;
	scanf("%d%d",&n,&y);
	for(i=0; i<=y/10000; i++){
		for(j=0; j<=y/5000; j++){
			if(i+j>n){
				break;
			}
			k=n-i-j;
			if(i*10000+j*5000+k*1000==y){
				printf("%d %d %d\n",i,j,k);
				return 0;
			}
		}
	}
	printf("-1 -1 -1\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
    long long n, m;
    cin >> n >> m;
    if (n==1 && m==1){
        cout << 1 << endl;
        return 0;
    }
    if (n==1 && 2<m){
        cout << m-2 << endl;
        return 0;
    }
    if (m==1 && 2<n){
        cout << n-2 << endl;
        return 0;
    }
    if (3>n || 3>m){
        cout << 0 << endl;
        return 0;
    }
    cout << (n-2) * (m-2) << endl;
    return 0;
}


Measured memory_bytes: 3604
def read_i
  gets.chomp.split(' ').map(&:to_i)
end

n, m = read_i
shops = n.times.map { read_i }

ans = 0
shops.sort_by { |e| e[0] }.each do |p, c|
  if m <= c # この店で終わり
    ans += p * m
    break
  end
  m -= c
  ans += p*c
end

puts ans

__END__
2 5
4 9
2 4


Measured memory_bytes: 12664
N = int(input())
vlist = list(map(int, input().split()))

while len(vlist) != 1:
    min1 = min(vlist)
    vlist.remove(min1)
    min2 = min(vlist)
    vlist.remove(min2)
    app = (min1+min2)/2
    vlist.append(app)

print(vlist[0])

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
using namespace std;
const int LEN = 2e5 + 10;
int p[LEN];
double sum[LEN];

int main() {
    int N, K;
    double ans = 0.0;
    cin >> N >> K;
    for (int i = 1; i <= N; i++) {
        cin >> p[i];
        sum[i] = sum[i - 1] + (1.0 + p[i]) / 2;
    }
    for (int i = 0; i <= N - K; i++) {
        ans = max(ans, sum[K + i] - sum[i]);
    }
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}

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

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  int a[n][m];
  int b[m][l];
  unsigned long int c[n][l];
  for(int i = 0;i < n; i++) {
    for(int j = 0;j < l; j++) {
      c[i][j] = 0;
    }
  }
  
  for(int i = 0;i < n; i++) {
    for(int j = 0;j < m; j++) {
      cin >> a[i][j];
    }
  }
  for(int i = 0;i < m; i++) {
    for(int j = 0;j < l; j++) {
      cin >> b[i][j];
    }
  }
 
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < l; j++) {
      for(int k = 0; k < m; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < l; j++) {
		std::cout << c[i][j];
		if (j != l - 1) std::cout << ' ';
	}
    std::cout << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3232
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int n; cin >> n;
  for (int i = 1; i <= 50000; i++) {
    if (int(i * 1.08) == n) {
      outl(i);
      return;
    }
  }
  outl(":(");
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

int main(){
  long long n,sum = 0;cin >> n;
  vector<long long> a(n);for(int i=0;i<n;i++)cin >> a[i];
  for(int i=0;i<n;i++)sum += a[i];
  cout << *min_element(a.begin(),a.end()) << " ";
  cout << *max_element(a.begin(),a.end()) << " ";
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3156
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
    ll n;scanf("%lld",&n);
    ll k;scanf("%lld",&k);
    vector<ll> a(n);
    for(int i = 0;i < n;i++)scanf("%lld",&a[i]);
    vector<ll> d(n-k+1);
    for (int i = 0; i < n-k+1; ++i)
    {
        d[i] = a[i+k-1] - a[i];
        if(a[i] > 0)d[i] += a[i];
        else if(a[i+k-1] < 0)d[i] -= a[i+k-1];
        else d[i] += min(-a[i],a[i+k-1]);
    }
    sort(d.begin(),d.end());
    printf("%lld\n",d[0]);
    return 0;
}


Measured memory_bytes: 1408
function Main(input) {
  input = input.split("\n");
  var count = Number(input[0]);
  var num_array = input[1].split(" ").map(Number);
  var tmp;
  console.log(num_array.join(" "));
  for(let i = 1; i < count; i++) {
    tmp = num_array[i];
    let j = i - 1;
    while(j >= 0 && num_array[j] > tmp) {
      num_array[j+1] = num_array[j--];
    }
    num_array[j+1] = tmp;
    console.log(num_array.join(" "));
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 16564
#include <stdio.h>

long long int gcd(long long int a,long long int b) {
	if(b == 0) return a;
	return gcd(b, a%b);
}

long long int lcm(long long int a, long long int b) {
	long long int g = gcd(a, b);
	return a/g*b;
}

// long long int lcms(long long int *a, int n) {
// 	int i;
// 	long long int ans;
// 	ans = 1;
// 	for (i=0; i<n; i++) {
// 		ans = lcm(ans, a[i]);
// 	}
// 	return ans;
// }

int main() {
	int n,i;
	scanf("%d", &n);
	long long int t[n];
	for (i=0; i<n; i++) {
		scanf("%llu", &t[i]);
	}
	long long int ans;
	ans = 1;
	for (i=0; i<n; i++) {
		ans = lcm(ans, t[i]);
	}
	printf("%llu\n", ans);
	return 0;
}

Measured memory_bytes: 128
import math
n, p = map(int, input().split())
ans = 1
for i in range(2, math.ceil(math.sqrt(p))):
    cnt = 0
    while p % i == 0 and p != 0:
        p //= i
        cnt += 1
    ans *= i ** (cnt // n)
ans *= p ** (1 // n)
print(ans)

Measured memory_bytes: 3060
fun main(args: Array<String>) {
    val s = readLine()?.split(" ")?.map(String::toInt)?.toIntArray() ?: return
    var count = 0
    (s[0]..s[1]).forEach(){
        count += if (it % s[2] == 0) 1 else 0
    }
    println(count)
}

Measured memory_bytes: 36484
from collections import deque
N = int( input())
A = list( map( int, input().split()))
B = list( map( int, input().split()))
ans = 0
kata = []
need = []
for i in range(N):
    if A[i] < B[i]:
        need.append(B[i] - A[i])
        ans += 1
    elif B[i] < A[i]:
        kata.append(A[i] - B[i])
need.sort()
kata.sort(key=None, reverse = True)
now = 0
for n in need:
    while n > now:
        if kata:
            now += kata.pop(0)
            ans += 1
        else:
            ans = -1
            break
    now -= n
    if ans == -1:
        break
print( ans)


Measured memory_bytes: 18740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int t;
ll l;
 
ll phi(ll x)
{
	ll res=x;
	for(int i=2;i*i<=x;i++)
	{
		if(x%i==0)
		{
			res=res/i*(i-1);
			while(x%i==0)
				x/=i;
		}
	}
	if(x>1)
		res=res/x*(x-1);
	return res;
}
ll ksm(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}
int main()
{
	int kase=0;
	cin>>l;
		ll mod=l/__gcd(7ll,l)*9ll;
		ll p=phi(mod);
		ll res=1e18;
		for(ll x=1;x*x<=p;x++)
		{
			if(p%x!=0) continue;
		if(ksm(10,x,mod)==1) res=min(res,x);
		if(ksm(10,p/x,mod)==1) res=min(res,p/x);
		}
		if(res==1e18)
			cout<<"-1"<<endl;
		else
			cout<<res<<endl;
    int ab;
    cin>>ab;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,C;
    cin >> N >> C;
    int cnt[C][100010] = {};
    vector<int> S(N),T(N),P(N);
    rep(i,0,N){
        cin >> S[i] >> T[i] >> P[i];
        cnt[P[i]-1][S[i]-1]++;
        cnt[P[i]-1][T[i]]--;
    }
    rep(i,1,100000)rep(j,0,C){
        cnt[j][i] += cnt[j][i-1];
    }
    int maxi = 0;
    rep(i,0,100000){
        int c = 0;
        rep(j,0,C){
            c += (cnt[j][i] > 0);
        }
        maxi = max(maxi, c);
    }
    cout << maxi << endl;
}

Measured memory_bytes: 13184
#include<iostream>

using namespace std;

int main(){

    int n;
    int m;
    int l;

    cin >> n;
    cin>>m;
    cin>>l;

    if ((n==m) && (n!=l))
        cout << "Yes" <<endl;
    else if ((n==l) && (n!=m))
        cout << "Yes" << endl;
    else if ((m==l) && (n!=m))
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;

}

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

int a,b,i=0,j,c;
typedef struct data{
 int x,p,r;
}DATA;
DATA n[1000];

int comp(const void *p,const void *q){
	DATA *a=(DATA *)p,*b=(DATA *)q;
	return b->p - a->p;
}

int main(){
	while(scanf("%d,%d",&a,&b)!=EOF){
		if(a==0 && b==0)break;
		n[i].x=a;n[i].p=b;i++;
	}
	qsort(n,i,sizeof(DATA),comp);
	n[0].r=1;
	for(j=1;j<i;j++){
		if(n[j-1].p - n[j].p==0)n[j].r=n[j-1].r;
		else n[j].r=n[j-1].r+1;
	}
	while(scanf("%d",&c)!=EOF){
		for(j=0;j<i;j++)if(n[j].x==c){printf("%d\n",n[j].r);break;}
	}
	return 0;
}

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

#define null				""
#define all(dat)			dat.begin(), dat.end()
#define over(msg)			cout << msg << endl, exit(0);
#define loop(i, to)			for (int i = 0; i < to; ++i)
#define cont(i, to)			for (int i = 1; i <= to; ++i)
#define foreach(i, dat)		for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long			num;

using namespace std;

int n, dat[100005][3], dp[100005][3], ans;

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	cont (i, n) {
		loop (j, 3) {
			cin >> dat[i][j];
		}
	}
	cont (i, n) {
		loop (j, 3) {
			loop (k, 3) {
				if (j == k)  continue;
				dp[i][j] = max(dp[i][j], dp[i - 1][k] + dat[i][j]);
			}
		}
	}
	loop (i, 3) {
		ans = max(ans, dp[n][i]);
	}
	cout << ans << endl;
}


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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}


int main(int argc, char const* argv[])
{
    string s;
    cin >> s;

    if (s[0] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
    else if (s[1] == s[2] && s[2] == s[3]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        s: String
    }
    let res = match &s[0..=2] {
        "SSS" => 0,
        "RSS" => 1,
        "SRS" => 1,
        "SSR" => 1,
        "RSR" => 1,
        "RRS" => 2,
        "SRR" => 2,
        "RRR" => 3,
        _ => panic!()
    };
    println!("{}", res);
}


Measured memory_bytes: 2152
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  
  if(a>=b) co(10);
  else co(0);
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[] a = sc.nextIntArray(n - 1);
    int[] ic = new int[n];
    for (int ai : a) {
      ic[ai - 1]++;
    }
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < n; i++) {
      if (sb.length() > 0) sb.append("\n");
      sb.append(ic[i]);
    }
    System.out.println(sb.toString());
  }
}

Measured memory_bytes: 54600
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pp pair<int, int>
#define ppp pair<pp, int>
#define pp4 pair<pp, pp>
#define pp3 pair<ll, pair<int, int> > 
#define fi first
#define se second
#define N  200020
#define mod 1000000007
#define inf 2000000001
#define esp 1e-9
#define BLOCK 333
#define BITNUM 555
#define BASE 311097
typedef long long ll;
// const ll oo = (ll)1e18 + 1;
using namespace std;
int k, n;
int a[N];

int main() {
    ios::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);
    
    cin >> k >> n;
    for (int i = 1; i <= n; i++) {
    	cin >> a[i];
    }

    int ret = a[n] - a[1];
    
    for (int i = 1; i < n; i++)
    	ret = min(ret, k - (a[i + 1] - a[i]));

    cout << ret;

    return 0;
}



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

int n, m;

long long ans = 0;

int main()
{	
	scanf( "%d%d", &n, &m );
	
	ans = 1900 * m + 100 * ( n - m );
	for( int i = 1; i <= m; i ++ )
		ans = ans * 2;
	
	printf( "%lld\n", ans );
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  bool ok = false;
  REP(x, 0, n + 1) {
    REP(y, 0, m + 1) {
      if ((n - x) * y + (m - y) * x == k) {
	ok = true;
      }
    }
  }
  cout << (ok ? "Yes" : "No") << "\n";
}


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

int main(){
    string s,t,u;
    int a,b;
    cin >> s >> t >> a>> b >> u;

    if (u == s) cout << a - 1 << " " << b << endl;
    else cout << a << " " << b - 1 << endl;

}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace arc064_a
{
    class Program
    {
        static void Main(string[] args)
        {
            long ret = 0;
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (x[1] < a[0])
            {
                ret += a[0] - x[1];
                a[0] = x[1];
            }
            for (int i = 1; i < x[0]; i++)
            {
                if (x[1] < a[i - 1] + a[i])
                {
                    ret += a[i - 1] + a[i] - x[1];
                    a[i] = x[1] - a[i - 1];
                }
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 30300
fun main(arg: Array<String>) {
    val K = nextLong()
    var ans = 0L
    for (a in 1 .. K)
    for (b in 1 .. K)
    for (c in 1 .. K)
        ans += gcd(a, gcd(b, c))
    return println(ans)
}
fun gcd(a: Long, b: Long): Long = if (a % b == 0L) b else gcd(b, a % b)
fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b

fun next() = readLine()!!
fun nextInt(offset: Int = 0) = Integer.parseInt(next()) + offset
fun nextLong() = next().toLong()


Measured memory_bytes: 34532
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int a[200000];
int n;
ll d[200000][5];
ll go(int N,int c)
{
	if(N==n)return 0;
	ll &ret=d[N][c];
	if(ret!=-1)return ret;
	ret=INF;
	if(c<4)ret=min(ret,go(N,c+1));
	if(c==0)
	{
		ret=min(ret,a[N]+go(N+1,c));
	}
	if(c==1)
	{
		ll t=0;
		if(a[N]==0)t=2;
		else if(a[N]&1)t=1;
		ret=min(ret,t+go(N+1,c));
	}
	if(c==2)
	{
		ll t=0;
		if(a[N]==0)t=1;
		else if(a[N]%2==0)t=1;
		ret=min(ret,t+go(N+1,c));
	}
	if(c==3)
	{
		ll t=0;
		if(a[N]==0)t=2;
		else if(a[N]&1)t=1;
		ret=min(ret,t+go(N+1,c));
	}
	if(c==4)
	{
		ret=min(ret,a[N]+go(N+1,c));
	}
	return ret;
}
int main() {
	MEM_1(d);
	scanf("%d",&n);
	fup(i,0,n-1,1)scanf("%d",a+i);
	printf("%lld",go(0,0));
}

Measured memory_bytes: 21376
N = int(input())
A = [int(x) for x in input().split()]

for i in range(N):
    if A[i] == 0:
        print(0)
        exit()

ans = A[0]
for i in range(1, N):
    ans *= A[i]
    if ans > 10**18:
        print(-1)
        exit()

print(ans)


Measured memory_bytes: 21348
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


bool path[101][101];

int main(){
    int n;
    cin >> n;
    int cnt = 0;
    if (n%2 == 1){
        for(int i = 1; i <= n/2; i++){
            path[i][n-i] = 1;
            cnt++;
        }
    }
    else{
        for(int i = 1; i <= n/2; i++){
            path[i][n-i+1] = 1;
            cnt++;
        }        
    }

    
    cout << n*(n-1)/2 - cnt << endl;
    for(int i = 1; i <= n; i++){
        for(int j = i+1; j <= n; j++) if(!path[i][j]) cout << i << " " << j << endl;
    }

    return 0;
}


Measured memory_bytes: 3640
#define DBG 0 //submit 0
#if DBG
    #include <algorithm>
    #include <ctime>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <iostream>
    #include <cmath>
    #include <numeric>
#else
    #include <bits/stdc++.h>
#endif

using namespace std;


int main(){
    int C,D,L,i,j,k,tmp = 0,tmpi = 0,ans = 1;
    int N;
    //string S;
    cin >> N;
    char s[N+5];
  	char a;
    for(i=0;i<N;i++){
        cin >> s[i];
    }
  
	a = s[0];
    for(i=1;i<N;i++){
      if(s[i] != a){
      	a = s[i];
        ans++;
      }
    }

  cout << ans << endl;
}


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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
const int mod = 1e9+7;
//Write From this Line

int main()
{
	int n ;
	cin >> n ;
	vector<int> a(n);
	rep(i,n) cin >>a[i];
	int A=0,B=0;
	SORT(a);
	rSORT(a);
	rep(i,n){
		if(i&1) B += a[i];
		else A+=a[i];
	}
	cout << A - B << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
//#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;
lli GCD(lli a, lli b) {
	lli x = more(a, b);
	lli y = less(a, b);
	lli r = x % y;
	while (r > 0) {
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}

int main(void)
{
	lli N, K; cin >> N >> K;
	vector<lli> A(N); 
	lli max = 0;
	rep(i, 0, N) {
		lli tmp; cin >> tmp;
		max = more(max, tmp);
		A[i] = tmp;
	}
	lli gcd = A[0];
	if (N >= 2)rep(i, 1, N)gcd = GCD(gcd, A[i]);

	if (K <= max && K % gcd == 0)cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;


	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define vi vector<int>
#define vll vector<long long>
#define ll long long
#define ull unsigned long long
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define nl cout<<'\n'
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define pll pair<long long,long long>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<ll,ll> >
#define si set<int>
#define sll set<long long>
#define all(v) (v).begin(),(v).end()
#define Unique(x)           (x).erase(unique(all(x)), x.end())
#define v_present(vec,x)  (find(all(vec),x)!=(vec).end())
#define present(myset,x)    ((myset).find(x)!=(myset).end())
#define Cprint(c)  for(auto i:(c)) { cout<<i<<" "; } nl
#define trace2(x,y) cout<<x<<" "<<y<<endl;
#define trace3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define trace4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<endl;
ll mod = 1e9+7;
const int MAX = 1e5+5;
using namespace std;
ll dp[100005];

int main()
{
    FAST_IO;
    int n,k;
    cin>>n>>k;
    int h[n+1];
    for(int i=1;i<=n;i++)
        cin>>h[i];
    dp[0]=0;
    dp[1]=0;
    dp[2]=dp[1]+abs(h[2]-h[1]);
    for(int i=3;i<=n;i++){
        dp[i]=1e15;
        for(int j=1;j<=k;j++){
            if(i-j>=1){
                dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
            }
        }
    }
    cout<<dp[n];

    return 0;

}


Measured memory_bytes: 1408
package main

import (
        "fmt"
)

func solution(n int, nums []int) []int {
        nums = append([]int{0}, nums...)
        bosses := make([]int, n)
        m := make(map[int]int)
        for _, num := range nums {
                m[num-1]++
        }
        for i := 0; i < n; i++ {
                bosses[i] = m[i]
        }
        return bosses
}

func main() {
        var n int
        fmt.Scan(&n)
        nums := make([]int, n-1)
        for i := 0; i < n-1; i++ {
                a := 0
                fmt.Scan(&a)
                nums = append(nums, a)
        }
        for _, num := range solution(n, nums) {
                fmt.Println(num)
        }
}

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

int main(){
	ll a, b, k;
  	cin >> a >> b >> k;
  
  	if(a > k){
    	cout << a - k << " " << b << endl;
    } else if(b > k - a){
		cout << 0 << " " << b - (k - a) << endl;
    } else {
    	cout << 0 << " " << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/


int N, M, R;
int d[202][202];
int r[202];
#define INF INT_MAX/2
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> R;
    rep(i, 0, R) cin >> r[i];

    rep(i, 0, N) rep(j, 0, N) {
        if (i == j) d[i][j] = 0;
        else d[i][j] = INF;
    }
    rep(i, 0, M) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        d[a][b] = c;
        d[b][a] = c;
    }

    rep(k, 0, N) rep(i, 0, N) rep(j, 0, N)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    vector<int> v;
    rep(i, 0, R) v.push_back(r[i] - 1);
    sort(v.begin(), v.end());
    int ans = INF;
    do {
        int sm = 0;
        rep(i, 0, R - 1) sm += d[v[i]][v[i + 1]];
        ans = min(ans, sm);
    } while (next_permutation(v.begin(), v.end()));
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
#define int long long
const int N = 1e5 + 10;
const int mod = 1e9 + 7;

int n, m;
int a[N], sum, sum1;

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

    cin >> n >> m;
    for (int i = 1; i <= n; ++i) cin >> a[i], sum += a[i];

    sort(a + 1, a + 1 + n);
    reverse(a + 1, a + 1 + n);

    for (int i = 1; i <= m; ++i)
    {
        if (a[i] * 4 * m < sum)
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public final class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);

        int n = stdIn.nextInt();
        int m = stdIn.nextInt();
        int[] l = new int [m];
        int[] r = new int [m];

        for(int i=0; i<m; i++){
            l[i] = stdIn.nextInt();
            r[i] = stdIn.nextInt();
        }

        int min = 0;
        int max = n-1;

        for(int i=0; i<m; i++){
            if(min<l[i]-1){
                min = l[i]-1;
            }
            if(r[i]-1<max){
                max = r[i]-1;
            }
        }

        if(min<=max){
            System.out.println(max-min+1);
        }else{
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 85900
/* created   : 2020-02-11 21:45:19
 * accepted  : 2020-02-11 21:53:28
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  string s, t; cin >> s >> t;
  int a, b; cin >> a >> b;
  string u; cin >> u;
  if (u == s) {
    a--;
  }
  else if (u == t) {
    b--;
  }
  cout << a << ' ' << b << '\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll N,P;
string S;
ll A[300020];
ll B[300020];
ll C[300020];
ll D[300020];

int main(){
    cin >> N >> P >> S;
    bool flag = 0;
    if(P == 2 || P == 5){
        flag = 1;
    }
    A[0] = 1;
    reverse(ALL(S));
    rep(i,200010){
        A[i+1] = (A[i] * 10) % P;
        A[i+1] %= P;
    }
    rep(i,N){
        ll n = S[i] - '0';
        B[i] = A[i] * n % P;
        while(B[i] < 0) B[i] += P;
        B[i] %= P;
    }
    rep(i,N){
        C[i+1] = C[i] + B[i];
        C[i+1] %= P;
        //cout << C[i+1] << ' ';
    }
    //cout << endl;
    ll ans = 0;
    if(!flag){
        map<ll,ll> mp;
        FOR(i,0,N+1){
            ans += mp[C[i]];
            mp[C[i]]++;
        }
    }else if(P == 2){
        rep(i,N){
            if((S[i] - '0') % 2 == 0){
                ans += N - i;
            }
        }
    }else{
        rep(i,N){
            if(S[i] == '5' || S[i] == '0'){
                ans += N - i;
            }
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 7556
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node{
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

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

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x!=NIL){
        y=x;
        if(z->key < x->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    z->parent = y;
    if(y==NIL){
        root = z;
    } else {
        if(z->key < y->key){
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder(Node *u){
    if(u==NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u){
    if(u==NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n,i,x;
    string com;

    scanf("%d",&n);

    for(i=0;i<n;i++) {
        cin >> com;

        if (com == "insert") {
            scanf("%d", &x);

            insert(x);
        } else if (com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}


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

int main(){
  int x;
  
  cin >> x;
  
 if(x == 7){
   cout << "YES" << endl;
 }
  else if(x == 5){
    cout << "YES" << endl;
  }
  else if(x == 3){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    if (v[0] * 100 + v[1] * 10 + v[2]) % 4 == 0 {
        println!("YES");
    } else {
        println!("NO");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
#include <string>

typedef long long ll;

#define debug(x) cerr << #x << ": " << x << "\n";
#define rep(i,n) for(int i=0; i<n; i++)

using namespace std;

int main(){
  ll A,B,C,K;
  cin >> A >> B >> C >> K;

  if(A>=K){
    cout << K << endl;
    return 0;
  }
  
  if(B>=K-A){
    cout << A << endl;
    return 0;
  }

  cout << A - (K-(A+B)) << endl;
  
}
      


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

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<char, int> mp;
    mp['R'] = 0;
    mp['G'] = 1;
    mp['B'] = 2;
    //R, G, B
    vector<vector<int>> acc(3, vector<int>(n + 1, 0));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            acc[j][i + 1] = acc[j][i];
        }
        acc[mp[s[i]]][i + 1]++;
    }
    long long ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (s[i] == s[j]) continue;
            int tmp = 0;
            int id = 3 - mp[s[i]] - mp[s[j]];
            if (j + j - i < n && mp[s[j + j - i]] == id) tmp--;
            if (j + 1 <= n) tmp += acc[id][n] - acc[id][j + 1];
            ans += tmp;
        }
    }
    cout << ans << endl;
}


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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  char s;
  cin >> s;
  if (s-'A' >= 0 && s-'A' <= 25)
    cout << 'A' << endl;
  else if (s-'a' >= 0 && s-'a' <= 25)
    cout << 'a' << endl;
}


Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N; cin >> N;
    string S; cin >> S;
    int Q; cin >> Q;
    while(Q--){
        int k; cin >> k;


        ll sum = 0;
        ll cntD = 0,cntDM = 0;
        ll cntM = 0;
        for(int i = 0; i < k;i++){
            if(S[i]=='D'){
                cntD++;
            }else if(S[i] == 'M'){
                cntM++;
                cntDM += cntD;
            }else if(S[i] == 'C'){
                sum += cntDM;
            }
        }
        for(int i = k; i < N;i++){
            if(S[i-k]=='D'){
                cntD--;
                cntDM -= cntM;
            }else if(S[i-k] == 'M'){
                cntM--;
            }


            if(S[i]=='D'){
                cntD++;
            }else if(S[i] == 'M'){
                cntM++;
                cntDM += cntD;
            }else if(S[i] == 'C'){
                sum += cntDM;
            }
        }
        cout << sum << endl;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    solve<ll>(0);
    //cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}

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

public class Main {
  private static boolean solve(int a, int b) {
    return a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int a = reader.nextInt();
    int b = reader.nextInt();
    out.println(solve(a, b) ? "Possible" : "Impossible");
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,c=0;
  cin >> n;
  int a[n];
  for(int i=1;i<=n;i++)
  {
    cin >> a[i];
  }
  for(int i=1;i<=n;i++)
  {
    if(i%2!=0)
    {
      if(a[i] % 2 !=0)
      {
        c++;
      }
    }
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define max 100005
#define nil -1

struct node
{
   int p,l,r;
};

node t[max];
int n,d[max],h[max];

void sd(int u,int p){
    if(u==nil) return;
    d[u]=p;
    sd(t[u].l,p+1);
    sd(t[u].r,p+1);
}

int sh(int u){
    int h1=0,h2=0;
    if(t[u].l!=nil){
        h1=sh(t[u].l)+1;
    }
    if(t[u].r!=nil){
        h2=sh(t[u].r)+1;
    }
    return h[u]=(h1>h2 ? h1 : h2 );
}

int gs(int u){
    if(t[u].p==nil){
        return nil;
    }
    if(t[t[u].p].l!=u&&t[t[u].p].l!=nil){
        return t[t[u].p].l;
    }
     if(t[t[u].p].r!=u&&t[t[u].p].r!=nil){
        return t[t[u].p].r;
    }
    return nil;
}

void print(int u){
    cout<<"node "<<u<<": ";
    cout<<"parent = "<<t[u].p<<", ";
    cout<<"sibling = "<<gs(u)<<", ";
    int deg=0;
    if(t[u].l!=nil){
        deg++;
    }
     if(t[u].r!=nil){
        deg++;
    }
    cout<<"degree = "<<deg<<", ";
    cout<<"depth = "<<d[u]<<", ";
    cout<<"height = "<<h[u]<<", ";

    if(t[u].p==nil){
        cout<<"root"<<endl;
    }else if(t[u].l==nil&&t[u].r==nil){
        cout<<"leaf"<<endl;
    }else{
        cout<<"internal node"<<endl;
    }
}

int main() {
   int v,r,l,root=0;
   cin>>n;
   for(int i=0;i<n;i++){
       t[i].p=nil;
   }
   for(int i=0;i<n;i++){
       cin>>v>>l>>r;
       t[v].l=l;
       t[v].r=r;
       if(l!=nil)t[l].p=v;
       if(r!=nil)t[r].p=v;
   }
   for(int i=0;i<n;i++){
       if(t[i].p==nil){
           root=i;
       }
   }

   sd(root,0);
   sh(root);

   for(int i=0;i<n;i++){
       print(i);
   }
    return 0;
}



Measured memory_bytes: 3112