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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
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);
}


int main() {
  int A, P;
  cin >> A >> P;
  cout << ((A * 3) + P) / 2 << endl;
}




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

#define int long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int N = 2e5 + 5;
const int inf = 1e16 + 2;



void solve(int z) {
    int n , m ;
    cin >> n >> m;
    vector<int> graph[n];
    int arr[n];
    for(int i = 0 , a; i < n ; i ++) cin >> arr[i] ;
    for(int i = 0 ; i < m ; i ++) {
        int a , b;
        cin >> a >> b;
        a -- , b --;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    int cnt = 0;
    for(int i = 0 ; i < n ; i ++) {
        int mx = 0;
        for(auto x : graph[i]) mx = max(mx , arr[x]);
        if(mx < arr[i]) cnt ++;
    }
    cout << cnt;
}

/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int x = 1;
    while(testcase --) {
        solve(x ++);
    }
    
    return 0;
}
 



Measured memory_bytes: 10248
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		a = b - a;
		a = (1 + a) / 2 * a;
		a = a -b;
		if (a>=1) {
			System.out.println(a);
		}
		else {
			System.out.println(1);
		}
		
		
	}
}


Measured memory_bytes: 22740
#include<stdio.h>
int f[1010][1010],y[1000010],x[1000010],l[1010][1010];
int main(){
  int Y[]={1,0,-1,0};
  int X[]={0,1,0,-1};
  int n,m,ny,nx,gy[11],gx[11],i,j,k,a=0,t,r;
  char s[1010][1010]={};
  scanf("%d %d %d",&n,&m,&k);
  for(i=1;i<=n;i++){
    for(j=1;j<=m;j++){
      scanf(" %c",&s[i][j]);
      if(s[i][j]=='S')s[i][j]='0';
      if('0'<=s[i][j]&&s[i][j]<='9')s[gy[s[i][j]-'0']=i][gx[s[i][j]-'0']=j]='.';
    }
  }
  //for(i=0;i<=k;i++)printf("%d %d\n",gy[i],gx[i]);
  for(i=0;i<k;i++){
    f[y[t=0]=gy[i]][x[  0]=gx[i]]=i+1;
    l[y[0]][x[0]]=0;
    for(r=1;r-t;t++){
      for(j=0;j<4;j++){
	ny=y[t]+Y[j];
	nx=x[t]+X[j];//printf("%d\n",f[ny][nx]);
	if(s[ny][nx]-'.'||f[ny][nx]==i+1)continue;
	f[y[r]=ny][x[r]=nx]=i+1;
	l[ny][nx]=l[y[t]][x[t]]+1;
	r++;
      }
    }//printf("%d\n",r);
    /*for(j=0;j<n;j++){
      for(t=0;t<m;t++)printf("%d ",l[j+1][t+1]);printf("\n");
      }//*/
    a+=l[gy[i+1]][gx[i+1]];
  }
  printf("%d\n",a);
  return 0;
}
	

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

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

string solve(int m, int f, int r) {
	if (m == -1 || f == -1)return "F";
	
	if (m + f >= 80) {
		return "A";
	} else if (m + f >= 65) {
		return "B";
	} else if (m + f >= 50 || r >= 50) {
		return "C";
	} else if (m + f >= 30) {
		return "D";
	} else {
		return "F";
	}
}

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

	int m, f, r;
	while (cin >> m >> f >> r) {
		if (m == -1 && f == -1 && r == -1) break;
		cout << solve(m, f, r) << endl;
	}
	return 0;
}

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

#define io ios::sync_with_stdio(false)
#define pb push_back
#define pqueue priority_queue
#define fi first
#define se second
#define ls rt<<1
#define rs rt<<1|1
#define sz(x) (int)(x).size()
#define dbg(x) cout<<#x<<" --- "<<x<<endl
#define mst(x,a) memset(x,a,sizeof(x))
#define fin(a) freopen(a,"r",stdin)
#define fout(a) freopen(a,"w",stdout)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); }
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r; }
const int inf=0x7fffffff;

int main(){
	int x;cin>>x;
	if(x>=30)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main(){
    char a;
    bool flag = 1;
    int counter = 0;
    for(int i = 0;i < 3;i++){
        cin >> a;
        if(a == 'R'&&flag){
            counter ++;
        }else if(a == 'S'){
            flag = 0;
        }
        if(a == 'R'&& !flag){
            counter = 1;
        }
        if(a == 'R')
        {
            flag = 1;
        }
    }
    cout << counter;
    return 0;
}


Measured memory_bytes: 3616
import java.io.*;

public class Main {

  static int n;
  
  public static void main(String[] args) throws Exception {
    
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] in = br.readLine().split(" ");
    n = Integer.parseInt(in[0]);

    br.close();

    System.out.println(n * n * n);

  }
}


Measured memory_bytes: 24204
from collections import deque

n = int(input())
lis = deque()
for i in range(n):
    input_line = input().split(" ")
    command = input_line[0]
    if len(input_line) > 1:
        d = input_line[1]
  
    if command == 'insert':
        lis.appendleft(d)
    elif command == 'delete':
        if d in lis:
            lis.remove(d)
        else:
            continue
    elif command == 'deleteFirst':
        lis.popleft()
    elif command == 'deleteLast':
        lis.pop()
   
print(' '.join(lis))


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

struct edge{
	int to;
	double dist;
};

int N;
long long xs,ys,xt,yt;
vector<vector<edge>> graph(1111);
vector<double> d(1111,1.0e40);

int main(){
	cin >> xs >> ys >> xt >> yt >> N;
	
	vector<long long> x;
	vector<long long> y;
	vector<long long> r;
	
	x.push_back(xs);
	y.push_back(ys);
	r.push_back(0);
	for(int i=0;i<N;i++){
		long long X,Y,R;
		cin >> X >> Y >> R;
		x.push_back(X);
		y.push_back(Y);
		r.push_back(R);
	}
	x.push_back(xt);
	y.push_back(yt);
	r.push_back(0);
	
	for(int i=0;i<N+1;i++)for(int j=i+1;j<N+2;j++){
		double D=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
		D=max(0.0,D-(r[i]+r[j]));
		edge e={j,D};
		graph[i].push_back(e);
		e.to=i;
		graph[j].push_back(e);
	}
	
	d[0]=0.0;
	
	priority_queue<pair<double,int>,vector<pair<double,int>>,greater<pair<double,int>>> que;
	
	que.push(make_pair(0.0,0));
	
	while(!que.empty()){
		pair<double,int> p=que.top();
		que.pop();
		int v=p.second;
		if(d[v]<p.first)continue;
		for(auto e:graph[v]){
			if(d[e.to]>d[v]+e.dist){
				d[e.to]=d[v]+e.dist;
				que.push(make_pair(d[e.to],e.to));
			}
		}
	}
	
	printf("%.10f\n",d[N+1]);
	return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

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

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=2019;

int main(){
    string N; cin >> N;
    int K; cin >> K;
    int size=N.size();
    vector<vector<vector<ll>>> dp(size, vector<vector<ll>>(2, vector<ll>(K+1, 0)));
    dp[0][0][0]=1;
    dp[0][0][1]=N[0]-'0'-1;
    dp[0][1][1]=1;
    for(int i=1; i<size; i++){
        for(int j=0; j<=K; j++){
            if(j == 0){
                dp[i][0][j]=dp[i-1][0][j];
            }
            else{
                dp[i][0][j]=dp[i-1][0][j-1]*9+dp[i-1][0][j];
                if(N[i] != '0'){
                    dp[i][0][j]+=dp[i-1][1][j-1]*(N[i]-'0'-1)+dp[i-1][1][j];
                    dp[i][1][j]=dp[i-1][1][j-1];
                }
                else dp[i][1][j]=dp[i-1][1][j];
            }
        }
    }
    cout << (dp[size-1][0][K]+dp[size-1][1][K]) << endl;
    return 0;
}

Measured memory_bytes: 3636
def init(init_val):
    for i in range(n):
        MI[i+num-1] = init_val[i]
        MA[i+num-1] = init_val[i]
    for i in range(num-2, -1, -1):
        MI[i] = min(MI[2*i+1], MI[2*i+2])
        MA[i] = max(MA[2*i+1], MA[2*i+2])


def update(k, x):
    k += num-1
    MI[k] = x
    MA[k] = x
    while k+1:
        k = (k-1)//2
        MI[k] = min(MI[k*2+1], MI[k*2+2])
        MA[k] = max(MA[k*2+1], MA[k*2+2])


def rangemin(p, q):
    if q <= p:
        return 1 << 100
    p += num-1
    q += num-2
    res = 1 << 100
    while q-p > 1:
        if p & 1 == 0:
            res = min(res, MI[p])
        if q & 1 == 1:
            res = min(res, MI[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = min(res, MI[p])
    else:
        res = min(min(res, MI[p]), MI[q])
    return res


def rangemax(p, q):
    if q <= p:
        return -1
    p += num-1
    q += num-2
    res = -1
    while q-p > 1:
        if p & 1 == 0:
            res = max(res, MA[p])
        if q & 1 == 1:
            res = max(res, MA[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = max(res, MA[p])
    else:
        res = max(max(res, MA[p]), MA[q])
    return res


n = int(input())
h = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

dp = [0 for _ in range(n+1)]

num = 2**(n).bit_length()
MI = [1 << 100]*2*num
MA = [-1]*2*num
init(dp)

for i in range(n):
    update(h[i], a[i] + rangemax(0, h[i]))

print(rangemax(0, n+1))


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

int a[] = {1, 3, 5, 7, 8, 10, 12};
int b[] = {4, 6, 9, 11};
int c[] = {2};

int x, y;

int main(){
	scanf("%d%d", &x, &y);
	int cnt = 0;
	for (int i = 0; i < 7; ++ i){
		if (a[i] == x || a[i] == y){
			++ cnt;
		}
	}
	if (cnt == 2){
		return printf("Yes\n"), 0;
	}
	cnt = 0;
	for (int i = 0; i < 4; ++ i){
		if (b[i] == x || b[i] == y){
			++ cnt;
		}
	}
	if (cnt == 2){
		return printf("Yes\n"), 0;
	}
	return printf("No\n"), 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;

int main ()
{
  prep();
  int n, k;
  cin >> n >> k;
  if (n == 1){
      cout << 0;
      return 0;
  }
  int arr[n];
  for (int i=0; i<n; i++){
      cin >> arr[i];
  }
  int maxest[n];
  int maxx = 0;
  for (int i=n-1; i>=0; i--){
      maxx = max(maxx, arr[i]);
      maxest[i] = maxx;
  }
  int biggest = 0;
  for (int i=0; i<n-1; i++){
      biggest = max(biggest, maxest[i+1]-arr[i]);
  }
  int cnt =0;
  for (int i=0; i<n-1; i++){
      int now = maxest[i+1]-arr[i];
      if (now == biggest){
          cnt++;
      }
  }
  cout << cnt;
  return 0; 
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int H,W;char A[1000][1000];
deque<pair<int,int>> task;
const int direct[8]={-1,0,1,0,0,-1,0,1};
int search(){
	int N=task.size();
	bool flag=false;
	int a,b,c,d;
    for(int j=0;j<N;j++){
        a=task.front().first;
        b=task.front().second;
        for(int i=0;i<4;i++){
            c=a+direct[i];
            d=b+direct[i+4];
            if(0<=c&&c<H&&0<=d&&d<W){
            	if(A[c][d]=='.'){
            	    flag=true;
            	    A[c][d]='#';
                    task.push_back(make_pair(c,d));
                }
            }
        }task.pop_front();
    }if(flag){
    	return 1;
    }else{
        return 0;
    }
}
int main(){
	cin>>H>>W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>A[i][j];
			if(A[i][j]=='#'){
				task.push_back(make_pair(i,j));
			}
		}
	}int ans=0;
	while(task.size()>0){
		ans+=search();
	}cout<<ans<<endl;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    char arr[n][n],ar[m][m];
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<n;j++)
            cin>>arr[i][j];
    }
    for (int i=0;i<m;i++)
    {
        for (int j=0;j<m;j++)
            cin>>ar[i][j];
    }
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<n;j++)
        {
            if(arr[i][j]==ar[0][0]&&i+m<=n&&j+m<=n)
            {
                int q=0;
                for (int k=i;k<i+m;k++)
                {
                    for (int h=j;h<j+m;h++)
                    {
                        if(ar[k-i][h-j]!=arr[k][h])
                        {
                            q=1;
                            break;
                        }
                    }
                }
                if(!q)
                {
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }

        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define X real()
# define Y imag()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef complex < ld > point;

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;

int n;
string s;
map < pair < string, string >, int > m;

int main(){
  cin >> n >> s;
  for(int i = 0; i < (1 << n); ++i){
    string p1, p2;
    for(int j = 0; j < n; ++j){
      if((i >> j) & 1){
        p1 += s[j];
      } else{
        p2 += s[j];
      }
    }
    m[make_pair(p1, p2)]++;
  }
  ll ans = 0;
  for(int i = 0; i < (1 << n); ++i){
    string p1, p2;
    for(int j = 0; j < n; ++j){
      if((i >> j) & 1){
        p1 += s[j + n];
      } else{
        p2 += s[j + n];
      }
    }
    reverse(p1.begin(), p1.end());
    reverse(p2.begin(), p2.end());
    ans += m[make_pair(p1, p2)];
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 87040
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line="";
		while((line = br.readLine())!=null){
			String[] s =line.split(" ");
			int[] a = new int[4];
			a[0] = Integer.parseInt(s[0]);
			a[1] = Integer.parseInt(s[1]);
			a[2] = Integer.parseInt(s[2]);
			a[3] = Integer.parseInt(s[3]);
			s = br.readLine().split(" ");
			int[] b = new int[4];
			b[0] = Integer.parseInt(s[0]);
			b[1] = Integer.parseInt(s[1]);
			b[2] = Integer.parseInt(s[2]);
			b[3] = Integer.parseInt(s[3]);
			int hit = 0;
			for(int i = 0;i<4;i++){
				if(a[i] == b[i]){
					hit++;
				}
			}
			int blow = 0;
			for(int i = 0;i<4;i++){
				for(int j = 0; j < 4;j++){
					if(a[i] == b[j] && i != j){
						blow++;
					}
				}
			}
			System.out.println(hit+" "+blow);
		}
	}

}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n, l;
    cin >> n >> l;
    vector<string> v;
    for(int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        v.pb(s);

    }
    sort(all(v));
    for(int i = 0; i < n; ++i) cout << v[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
// 問題の URL を書いておく
// https://atcoder.jp/contests/abc158/tasks/abc158_d

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#include <cstring>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

const int MaxSLen = 100000 + 1;
const int MaxQueryLen = 2 * 100000 + 1;

char ans[MaxSLen + MaxQueryLen * 2 + 2] = {};

int main(int, const char**)
{
    string s;
    cin >> s;
    int head = MaxQueryLen;
    int tail = head + s.size();
    memcpy(&ans[head], s.c_str(), s.size());
    int q;
    cin >> q;
    int mode = 0;
    rep(i, q)
    {
        int m;
        cin >> m;
        if(m == 1)
        {
            mode = (mode + 1) % 2;
        }
        else
        {
            int f;
            char c;
            cin >> f >> c;
            if((mode == 0 && f == 1) || (mode == 1 && f == 2))
            {
                head--;
                ans[head] = c;
            }
            else
            {
                ans[tail] = c;
                tail++;
            }
        }
    }
    if(mode == 1)
    {
        reverse(&ans[head], &ans[tail]);
    }
    printf("%s\n", &ans[head]);
    return 0;
}


Measured memory_bytes: 4064
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef complex<long double> cmplx;
const long double pi = 3.14159265358979323846;
const int inf = (int)2e+9 + 2;
const int mod = 1'000'000'007;//998244353;
const long double eps = 1e-8;
const int N = 1'000'000;

int n, k, q;
string s;

void solve(int test)
{
  cin >> n >> s >> q;
  for (int i = 0; i < q; ++i) {
    cin >> k;
    int64 d = 0;
    int64 m = 0;
    int64 dm = 0;
    int64 dmc = 0;
    for (int i = 0; i < k; ++i) {
      if (s[i] == 'D')
        ++d;
      else if (s[i] == 'M') {
        dm += d;
        ++m;
      }
      else if (s[i] == 'C')
        dmc += dm;
    }
    for (int i = k; i < n; ++i) {
      if (s[i - k] == 'D') {
        --d;
        dm -= m;
      }
      else if (s[i - k] == 'M')
        --m;

      if (s[i] == 'D')
        ++d;
      else if (s[i] == 'M') {
        dm += d;
        ++m;
      }
      else if (s[i] == 'C')
        dmc += dm;
    }
    cout << dmc << '\n';
  }
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
      solve(i);
  //cout << endl << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count();
  return 0;
}



Measured memory_bytes: 1948
import math
K = int(input())
cnt = 0
for a in range(1,K + 1):
    for b in range(1,K + 1):
        for c in range(1,K + 1):
            g = math.gcd(a,b)
            g = math.gcd(g,c)
            cnt += g
print(cnt)

Measured memory_bytes: 69048
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll MOD=1e9+7 ;
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; }

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    
    int m,d;
    cin >> m >> d;

    int ans = 0;
    rep(i,m) {
        rep(j,d)
        {
            int d1 = (j+1)%10;
            int d10 = (j+1)/10;

            if (d1>=2 && d10>=2 && d1*d10 == i+1) ans++;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define tms(x) ___ = x; while(___--)
#define D(x) cout<<"D: "<<#x<<'='<<x<<endl;
#define R(x, l) cout<<"R: Array "<<#x<<endl; rep(i, 0, l) cout<<' '<<i<<':'<<*(x+i)<<endl;
#define pb push_back
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int ___;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
signed main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string str = next<string>();
	if (str[2] == str[3] && str[4] == str[5]) puts("Yes");
	else puts("No");
	return ~~(0-0);
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<map>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define cout(x) cout << x << endl;
// for (int i = 0; i < N; ++i) cin >> A[i];
typedef vector<int> vint;
typedef vector<long> vl;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef map<string, int> mapstri;
typedef map<string, int> mapii;

int main () {
    string s;
    cin >> s;
    int n = 0;
    n = s.length();
    bool mae = true;
    int nn = (n - 1) / 2;
    
    for(int i = 0; i < (nn / 2); ++i) {
       if(s[i] != s[nn - i - 1]) {
           mae = false;
       }
    }
    for(int i = nn + 1; i < n - nn + 1 ; ++i) {
       if(s[i] != s[n + nn - i]) {
           mae = false;
       }
    }
    for(int i = 0; i < nn; ++i) {
       if(s[i] != s[n - i - 1]) {
           mae = false;
       }
    }
    if (mae == true) cout("Yes") 
    else cout("No")
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    string s;
    cin >> s;
    if(s=="ABC"){
        cout << "ARC" << endl;
    }
    else
    {
        cout << "ABC" << endl;
    }

    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
void first(){
  cout << "Alice" << endl;
  exit(0);
}

void second(){
  cout << "Borys" << endl;
  exit(0);
}

int main() {
  ll n, a, b; cin >> n >> a >> b;
  if((b-a-1)%2 == 0){
    second();
  }else{
    first();
  }
}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]

O = set(sorted(A)[::2])
E = set(sorted(A)[1::2])

ans = 0
for i in range(N):
    if i % 2 == 0 and A[i] not in O:
        ans += 1
    elif i % 2 == 1 and A[i] not in E:
        ans += 1
print(ans//2)


Measured memory_bytes: 58712
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main(){
 
    int n,k,x,y;

    cin >> n>>k>>x>>y;

    if(n>k){
        cout << k*x+(n-k)*y <<endl;
    }else{
        cout << n*x  <<endl;
    }

    return 0;

}

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

int main()
{
	int N, sum = 0;

	cin >> N;

	int n, m;
	for (int i = 0; i < N; i++)
	{
		cin >> n >> m;
		sum += m + 1 - n;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,C;
	cin>>N>>C;
	vector<P> st(N);
	vector<ll> c(N);
	REP(i,N) cin>>st[i].first>>st[i].second>>c[i];
	REP(i,N) {
		st[i].first*=2;
		st[i].second*=2;
	}
	vector<vector<ll>> tim(C,vector<ll>(200010,0));
	REP(i,N) {
		tim[c[i]-1][max(0ll,st[i].first-1)]++;
		tim[c[i]-1][st[i].second+1]--;
	}
	REP(i,C) {
		REP(j,200010) {
			if(j!=0) tim[i][j]+=tim[i][j-1];
		}
	}
	ll ret=0;
	REP(i,200010) {
		ll cnt=0;
		REP(j,C) {
			if(tim[j][i]) cnt++;
		}
		ret=max(ret,cnt);
	}
	cout<<ret<<endl;
}


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

int main(){
  int n;
  cin>>n;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  ll ans=0;
  while(1){
    bool go=true;
    rep(i,n){
      if(a[i]>=n){
        go=false;
        ans+=a[i]/n;
        rep(j,n){
          if(i!=j){
            a[j]+=a[i]/n;
          }
        }
      }
      a[i]%=n;
    }
    if(go)break;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3576
#include <iostream>
using namespace std;
int main(){
	int m[10];
	for(int i=0;i<10;i++) cin >> m[i];
	while(1){
		bool j = true;
		for(int i=0;i<9;i++){
			if(m[i]<m[i+1]){
				int t = m[i];
				m[i] = m[i+1];
				m[i+1] = t;
				j = false;
			}
		}
		if(j) break;
	}
	for(int i=0;i<3;i++) cout << m[i] << endl;
}

Measured memory_bytes: 1160
# https://atcoder.jp/contests/abc128/submissions/7097699
import sys
input = sys.stdin.readline

from bisect import bisect_left

n,q = map(int, input().split())
road = [list(map(int, input().split())) for i in range(n)]
road.sort(key=lambda x: x[2])
start = [int(input()) for i in range(q)]

skip = [-1]*q
ans = [-1]*q
for s,t,x in road:
    left = bisect_left(start, s-x)
    right = bisect_left(start, t-x)
    # [left, right)をxで埋める
    # すでに存在するところ(skipがあるところ)は飛ばす
    while left < right:
        if skip[left] == -1:
            ans[left] = x
            skip[left] = right
            left += 1
        else:
            left = skip[left]
print(*ans, sep="\n")

Measured memory_bytes: 112732
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
int n,k;
cin >> n >> k;
vector<double>a(n+1,0),b(n);
for(int i=0;i<n;i++){
    cin >> b.at(i);
    double che = 0;
    for(int j=1;j<=b.at(i);j++){
        che+=j/b.at(i);
    }
    b.at(i)=che;
}
for(int i=1;i<=n;i++){
    a.at(i)=a.at(i-1)+b.at(i-1);
}
double saidai = -1;
for(int i=k;i<=n;i++){
    double goukei = a.at(i)-a.at(i-k);
    if(goukei>saidai){
        saidai = goukei;
    }
}
cout << fixed<<setprecision(20);
cout << saidai << endl;
}





Measured memory_bytes: 3328
// 単一始点最短経路 ( ダイクストラ法 : 優先度付きキュー )
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

#include<queue>

using namespace std;

static const int MAX_N = 10000;
static const int INFTY = (1 <<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

class q_element
{
    public:
        // 各頂点のNo.と経路の値
        int vertex_num;
        int vertex_val;

        // コンストラクタ
        q_element(int a, int b)
        {
            vertex_num = a;
            vertex_val = b;
        };
};

// ">" のオーバーロード [ receive_val ] を基準に大小比較を行う
bool operator> (const q_element &q_element_1, const q_element &q_element_2)
{
    return q_element_1.vertex_val > q_element_2.vertex_val;
};

// q_elementクラスのオブジェクトを昇順にするためのキューの定義
std::priority_queue< q_element,
                     std::vector<q_element>,
                     std::greater<q_element> > pqEle;

// 隣接リストを作成する ( 頂点と重みの情報を格納する )
vector<q_element> v_Link[MAX_N + 1];

int n;

// ダイクストラ法を実施するメソッド( 優先度付きキュー )
int Dijkstra_priority_queue(int start_v);

int main(void)
{

    cin >> n;

    int k, c, u, v;
    q_element q_entity(0, 0);

    for(int i = 0; i < n; i++)
    {
        cin >> u >> k;

        for(int j = 0; j < k; j++)
        {
            cin >> v >> c;

            // 隣接リストの作成 ( 頂点と重みを設定する )
            q_entity.vertex_num = v;
            q_entity.vertex_val = c;

            v_Link[u].push_back(q_entity);
        }
    }

    // 優先度付きキューを用いたダイクストラ法
    Dijkstra_priority_queue(0);

    return 0;

}

// 優先度付きキューを用いたダイクストラ法を実施するメソッド
// start_v : スタートする頂点のNo.
int Dijkstra_priority_queue(int start_v)
{
    int u, v, minv;
    int d[MAX_N], p[MAX_N], color[MAX_N];

    for(int i = 0; i < n; i++)
    {
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }

    // 初期値の設定 ( 頂点 : 0 を開始点とする)
    d[start_v] = 0;
    color[start_v] = GRAY;
    // キューに要素を入れる
    pqEle.push( q_element(start_v, 0) );

    while( !pqEle.empty() )
    {

        // 最小の値を持つ頂点を取り出す ( キューの先頭 )
        u = pqEle.top().vertex_num;
        minv = pqEle.top().vertex_val;
        pqEle.pop();

        // 訪問完了
        color[u] = BLACK;

        for(int v_num = 0; v_num < v_Link[u].size(); v_num++)
        {
            // 隣接リストから接続している要素を取得する
            v = v_Link[u][v_num].vertex_num;

            if( color[v] != BLACK )
            {
                // u → v の経路の中で, vのコストが最小のものが見つかれば更新する
                if( d[v] > d[u] + v_Link[u][v_num].vertex_val )
                {
                    // コストの記録
                    d[v] = d[u] + v_Link[u][v_num].vertex_val;
                    // 頂点 v の親を記録する
                    p[v] = u;
                    // 訪問状態の記録
                    color[v] = GRAY;

                    // キューに要素を入れる
                    pqEle.push( q_element(v, d[v]) );
                }
            }
        }
    }

    // 結果の表示
    for(int i = 0; i < n; i++)
    {
        cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;
    }

    return 0;
}



Measured memory_bytes: 7720
h,w,d = map(int,raw_input().split())

field = []

for i in range(h):
	field.append(map(int,raw_input().split()))

distance = [0 for i in range(90001)]


n = int(input())

arr = [[] for i in range(90001)]

inputs = []

for i in range(n):
	inputs.append(map(int,raw_input().split()))


for i in range(h):
	for j in range(w):
		arr[field[i][j]] = [i+1,j+1]

for i in range(d+1,h*w+1):
	distance[i] = distance[i-d] + abs(arr[i][0] - arr[i-d][0]) + abs(arr[i][1] - arr[i-d][1])


for i in range(n):
	l,r = inputs[i]

	print distance[r]-distance[l]

Measured memory_bytes: 38976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  ll k;
  cin>>k;
  string str;
  cin>>str;
  ll n=str.length();
  if(n<=k)
    cout<<str;
  else
  {
    cout<<str.substr(0,k)<<"...";
  }
  
  return 0;
}

Measured memory_bytes: 3508
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(input())
point=0
double=0
def put(what):
    if what=="s":
        return R
    if what=="r":
        return P
    if what=="p":
        return S
#print(T)
for i in range(K):
    check=[]
    for j in range(N//K+1):
          if i+K*j<N:
              check+=T[i+K*j]
    #print(check)####
    point+=put(T[i])
    for j in range(len(check)-1):
        if check[j]==check[j+1]:
            check[j+1]="n"#double
        else:
            point+=put(check[j+1])
    #print(point)#####
print(point)
      
        
    

Measured memory_bytes: 4788
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	int ans = 0;
	map<pair<int,int>, int> c;
	
	cin>>N;
	
	for(int i = 0; i < N; i++){
		int x, y, w;
		
		cin>>x>>y>>w;
		
		c[{x, y}] += w;
	}
	for(pair<pair<int,int>,int> p : c){
		int x = p.first.first;
		int y = p.first.second;
		int con = 0;
		
		if(c.count({x,y})) con += c.find({x,y})->second;
		if(c.count({x,y+1})) con += c.find({x,y+1})->second;
		if(c.count({x+1,y})) con += c.find({x+1,y})->second;
		if(c.count({x+1,y+1})) con += c.find({x+1,y+1})->second;
		
		if(con > ans) {
			ans = con;
		}
		con = 0;
		
		if(c.count({x,y})) con += c.find({x,y})->second;
		if(c.count({x,y-1})) con += c.find({x,y-1})->second;
		if(c.count({x+1,y})) con += c.find({x+1,y})->second;
		if(c.count({x+1,y-1})) con += c.find({x+1,y-1})->second;
		
		if(con > ans) {
			ans = con;
		}
		con = 0;
		
		if(c.count({x,y})) con += c.find({x,y})->second;
		if(c.count({x,y+1})) con += c.find({x,y+1})->second;
		if(c.count({x-1,y})) con += c.find({x-1,y})->second;
		if(c.count({x-1,y+1})) con += c.find({x-1,y+1})->second;
		
		if(con > ans) {
			ans = con;
		}
		// con = 0;
		
		// if(c.count({x,y})) con += c.find({x,y})->second;
		// if(c.count({x,y-1})) con += c.find({x,y-1})->second;
		// if(c.count({x-1,y})) con += c.find({x-1,y})->second;
		// if(c.count({x-1,y-1})) con += c.find({x-1,y-1})->second;
		
		// if(con > ans) {
			// ans = con;
		// }
	}
	
	cout<<ans<<" / "<<1<<endl;
	
	return 0;
}


Measured memory_bytes: 9476
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <math.h>
typedef long long ll;
using namespace std;

int main() {
	int n,k;
	cin>>n>>k;
    string a[n+1];
    for(int i=0;i<n;i++){cin>>a[i];}
    sort(a,a+n);
    for(int i=0;i<n;i++){
    	cout << a[i];
    }
    cout << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int cnt, sum = 0, t;
		for (int i = 1; i <= n; i = i + 2) {
			cnt = 0;
			t = i;
			for (int j = 1; j <= i; j = j + 2) {
				if (t % j == 0) {
					cnt++;
				}
			}
			if (cnt == 8) {
				sum++;
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
long long a[200000];
int main()
{
	long long n;
	cin>>n;
	for (long long i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	long long ans = 0;
	for (long long i = 1; i < n; ++i)
	{
		if(a[i]<a[i-1])
		{
			ans += a[i-1]-a[i];
			a[i] = a[i-1];
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 5152
while True:
    
    h,w=map(int,input().split())
    if h ==0 and w ==0:
        break
    
    for i in range(h):
        for k in range(w):
            if (i+k)%2==0:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()
        


Measured memory_bytes: 7000
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int m=0,f=0,r=0,x=0;
    while(1){
        scanf("%d %d %d",&m,&f,&r);
        if(m==-1 && f==-1 && r==-1){
            break;
        }else{
            x = m+f;
            if(m==-1 || f==-1){
                printf("F\n");
            }else if(x>=80){
                printf("A\n");
            }else if(x>=65 && x<80){
                printf("B\n");
            }else if(x>=50 && x<65){
                printf("C\n");
            }else if(x>=30 && x<50){
                if(r>=50){
                    printf("C\n");
                }else{
                    printf("D\n");
                }
            }else{
                printf("F\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 584
function Main(input) {
    input = input.split('/');

    var ms = Date.parse(`${input[0]}-${input[1]}-${input[2]}`);

    if (ms < 1556636400000) {
        return console.log('Heisei');
    } else {
        return console.log('TBD');
    }
}

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

Measured memory_bytes: 7368
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int ans;
int h1, m1, h2, m2, k;

int main(void) {
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    ans = (h2*60+m2-k) - (h1*60+m1);

  
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 5e5 + 5;
typedef long long ll; 
using namespace std;

int n;
ll ans, tmp; 
char s[N]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin);
#endif
	scanf("%s", s + 1), n = strlen(s + 1);
	for(int x, i = 1; i <= n; i++)
		for(int j = i; j <= n; j++)
		{
			x = 1;
			for(int k = 1; k < i - 1; k++) x = x * 2; 
			for(int k = j + 1; k < n; k++) x = x * 2; 
			tmp = s[i] - '0'; 
			for(int k = i + 1; k <= j; k++) tmp = tmp * 10 + s[k] - '0'; 
			ans += tmp * x; 
		}
	cout<<ans<<endl; 
	return 0; 
}


Measured memory_bytes: 3256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 10005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

bool dp[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	dp[0]=true;
	for(int i=0;i<n;i++)
	{
		int a;
		scanf("%d",&a);
		for(int j=SIZE-1;j>=a;j--) dp[j]|=dp[j-a];
	}
	for(int i=SIZE-1;i>=0;i--)
	{
		if(i%10!=0&&dp[i])
		{
			printf("%d\n",i);
			return 0;
		}
	}
	puts("0");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
#define rSORT(v) std::sort(v.begin(), v.end(),std::greater<int>())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans1=0, ans2 = 0;
    if (count(s.begin(), s.end(), s[0]) == s.size()) {
        cout << s.size() / 2 << endl;
        return 0;
    }
    for (size_t i = 0; i < s.size(); ++i) {
        if ((i % 2 == 0 && s[i] != '1')||(i%2==1&&s[i]!='0')) {
            ans1++;
        }

        if ((i % 2 == 0 && s[i] != '0') || (i % 2 == 1 && s[i] != '1')) {
            ans2++;
        }
        
    }
    cout << min(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 512
// ref. https://www.youtube.com/watch?v=bHzohtVsG0Q&feature=youtu.be

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

const int MX = 2005;
bool d[3][3][MX]; // d[i][j][k] .. check (i,j) pair with k diff

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  vector<string> s(3);
  rep(i, 3) {
    cin >> s[i];
  }

  int ans = 3 * MX;
  sort(s.begin(), s.end());
  do {
    rep(i,3)rep(j,3)rep(k,s[i].size()) {
      if (i >= j) { continue; } // only check (i < j)

      // Check (i,j) pair with k difference.
      // check s[i][ni] and s[j][nj]. nj = ni-k.
      bool ok = true;
      for (int ni = k; ni < s[i].size(); ++ni) {
        int nj = ni-k;
        if (nj >= s[j].size()) { break; }
        if (s[i][ni] == '?' || s[j][nj] == '?') { continue; }
        if (s[i][ni] != s[j][nj]) { ok = false; }
      }
      d[i][j][k] = ok;
    }

    auto f = [&](int i, int j, int k) {
      // If diff is larger thant the size of i, it is true.
      if (k >= s[i].size()) { return true; }
      return d[i][j][k];
    };

    rep(x,MX)rep(y,MX) {
      // diff x at (0,1), diff y at (1,2)
      if (!f(0,1,x)) { continue; }
      if (!f(1,2,y)) { continue; }
      if (!f(0,2,x+y)) { continue; }
      int now = 0;
      now = max<int>(now, s[0].size());
      now = max<int>(now, x+s[1].size());
      now = max<int>(now, x+y+s[2].size());
      ans = min(ans, now);
    }
  } while (next_permutation(s.begin(), s.end()));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
K = int(input())
A, B = map(int, input().split())
List = []
x = 0
cnt = 1
state = 0
for n in range((B-A)+1):
    List.append(A + n)

for i in range(len(List)):
    if List[i]%K == 0:
        print('OK')
        state = 1
        break

if state == 0:
    print('NG')

Measured memory_bytes: 9196
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def main():
    N, X, *xn = map(int, open(0).read().split())
    ans = abs(X - xn[0])
    for x in xn:
        dif = abs(X - x)
        if dif % ans:
            ans = gcd(ans, dif)
    print(ans)
    return


main()


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

int main() {
  int a, b; cin >> a >> b;
  string s; cin >> s;
  rep(i,s.size()) {
    if (i < a && s[i] == '-') {
      cout << "No" << endl;
      return 0;
    }
    if (i == a && s[i] != '-') {
      cout << "No" << endl;
      return 0;
    }
    if (a+1 < i && s[i] == '-') {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  
  int sum = 0;
  for (int i = 1;i<n;i++){
    if (s.at(i) == 'E'){
      sum++;
    }
  }
  
  int minnum = sum;
  for(int i = 1;i<n;i++){
    if (s.at(i-1) == 'W'){
      sum++;
    }
    if (s.at(i) == 'E'){
      sum--;
    }
    minnum = min(minnum,sum);
  }
  cout << minnum << endl;
}

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

int main(){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << x2 + y1 - y2 << " ";
    cout << y2 + x2 - x1 << " ";
    cout << x1 + y1 - y2 << " ";
    cout << y1 + x2 - x1 << endl;
}

Measured memory_bytes: 256