akhauriyash/Code-Regression huggingface dataset:
/*
这道题怎么这么熟悉哈
简单的转化， 答案等于块内蓝格子数量减去块内每个点非向外连得度数


蓝格子数量可以直接二位前缀和求
非向外连得度数？？ 这个怎么求， 对于每一行每一列都维护向左向右的前缀和即可

正解应该不是这样吧QWQ


*/

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#define ll long long
#define M 2011
using namespace std;
int read() {
	int nm = 0, f = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
	return nm * f;
}

int hu[M][M], hd[M][M], lx[M][M], ly[M][M], sum[M][M], du[M][M];
char s[M];
int  note[M][M];
int q, n, m;
int main() {
	n = read(), m = read(), q = read();
	for(int i = 1; i <= n; i++) {
		scanf("%s", s + 1);
		for(int j = 1; j <= m; j++) note[i][j] = s[j] - '0';
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + note[i][j];
			if(note[i][j]) {
				if(note[i - 1][j]) du[i][j]++;
				if(note[i + 1][j]) du[i][j]++;
				if(note[i][j - 1]) du[i][j]++;
				if(note[i][j + 1]) du[i][j]++;
			}
			du[i][j] += du[i - 1][j] + du[i][j - 1] - du[i - 1][j - 1];
		}
	}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++) {
			hu[i][j] = hu[i][j - 1] + (note[i][j] && note[i - 1][j]);
			hd[i][j] = hd[i][j - 1] + (note[i][j] && note[i + 1][j]);
			lx[i][j] = lx[i - 1][j] + (note[i][j] && note[i][j - 1]);
			ly[i][j] = ly[i - 1][j] + (note[i][j] && note[i][j + 1]);
		}
	while(q--) {
		int a = read(), b = read(), c = read(), d = read();
		int op = (du[c][d] - du[a - 1][d] - du[c][b - 1] + du[a - 1][b - 1]) -( hu[a][d] - hu[a][b - 1]
		     + hd[c][d] - hd[c][b - 1] + lx[c][b] - lx[a - 1][b] + ly[c][d] - ly[a - 1][d]);
		int od = sum[c][d] - sum[a - 1][d] - sum[c][b - 1] + sum[a - 1][b - 1];
	//	cout << od << " " << op << "\n";
		cout << od - op / 2<< "\n";
	}
	return 0;
}

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

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

ll INF = 1e10;
vector<int> v(100110);
vector<ll> dp(100110, INF);

int main(){
    int N;
    cin >> N;
    
    dp[0] = 0;
    rep(i, N) {
        chmin(dp[i+1], dp[i]+1);
        
        for(int j=6; i+j <= N+1; j*=6)
            chmin(dp[i+j], dp[i]+1);
            
        for(int j=9; i+j <= N+1; j*=9)
            chmin(dp[i+j], dp[i]+1);
    }
    
    cout << dp[N] << endl;
    return 0;
}


Measured memory_bytes: 4580
n=eval(input())
arr=[]
for i in range(n):
    arr+=[input()]
a=arr.count("AC")
b=arr.count("WA")
c=arr.count("TLE")
d=arr.count("RE")
print("AC x {}".format(a))
print("WA x {}".format(b))
print("TLE x {}".format(c))
print("RE x {}".format(d))


Measured memory_bytes: 16160
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ZYCSwing
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        Map<Integer, Integer> map;
        int[][] a;
        int[][] dp;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            map = new HashMap<>();
            int h = in.nextInt(), w = in.nextInt(), d = in.nextInt();
            a = new int[h][w];
            dp = new int[h * w + 1][17];

            for (int i = 0; i < h; ++i)
                for (int j = 0; j < w; ++j) {
                    a[i][j] = in.nextInt();
                    map.put(a[i][j], i * w + j);
                }

            for (int val = 1; val + d <= h * w; ++val) {
                int x = map.get(val) / w;
                int y = map.get(val) % w;
                int xx = map.get(val + d) / w;
                int yy = map.get(val + d) % w;
                dp[val][0] = Math.abs(x - xx) + Math.abs(y - yy);
            }

            for (int i = 1; i < 17; ++i) {
                for (int val = 1; val + (1L << i) * d <= h * w; ++val) {
                    dp[val][i] = dp[val][i - 1] + dp[val + (1 << (i - 1)) * d][i - 1];
                }
            }

            int q = in.nextInt();

            int l, r;
            for (int i = 0; i < q; ++i) {
                l = in.nextInt();
                r = in.nextInt();

                int diff = r - l;
                int step = diff / d;
                int res = 0;
                int cur = l;

                for (int j = 16; j >= 0; --j) {
                    if (((1 << j) & step) != 0) {
                        res += dp[cur][j];
                        cur = cur + (1 << j) * d;
                    }
                }
                out.println(res);
            }
        }

    }
}



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

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

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

using namespace std;

const int MAX = 8;
const int INF = (1<<25);

struct State{
  int x,y,t,bx,by;
  State(){}
  State(int x, int y, int t, int bx, int by):x(x),y(y),t(t),bx(bx),by(by){}
  bool operator < (const State& s) const { return t > s.t;}
};

int M[MAX][MAX];
int T[MAX][MAX][MAX][MAX];
//T[i][j][k][l]:= shortest time i,j (y,x) when box is on k,l (y,x)

int sx,sy,gx,gy,sbx,sby;
int w,h;

bool isInside(int x, int y){ return 0<=x&&x<w&&0<=y&&y<h;}

void init(){
  fill(T[0][0][0],T[0][0][0]+MAX*MAX*MAX*MAX,INF);
}

void input(){
  for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++){
      cin >> M[i][j];
      if(M[i][j] == 2) sbx=j,sby=i;
      if(M[i][j] == 3) gx=j,gy=i;
      if(M[i][j] == 4) sx=j,sy=i;
    }
}

void solve(){

  int dx[] = {0,1,0,-1};
  int dy[] = {-1,0,1,0};
  
  T[sy][sx][sby][sbx] = 0;
  priority_queue<State> Q;
  Q.push(State(sx,sy,0,sbx,sby)); 

  while(!Q.empty()){
    State now = Q.top();
    Q.pop();

    for(int i = 0; i < 4; i++){
      State nex = now;
      nex.x += dx[i];
      nex.y += dy[i];

      if(!isInside(nex.x,nex.y) || M[nex.y][nex.x] == 1) continue;

      if(nex.x == nex.bx && nex.y == nex.by){
	//move cargo
	nex.bx += dx[i];
	nex.by += dy[i];
	nex.t++;
	if(isInside(nex.bx,nex.by) && M[nex.by][nex.bx] != 1 && T[nex.y][nex.x][nex.by][nex.bx] > nex.t){
	  T[nex.y][nex.x][nex.by][nex.bx] = nex.t;
	  Q.push(nex);
	}
      
      }else{
	//move myself
	if(T[nex.y][nex.x][nex.by][nex.bx] > nex.t){
	  T[nex.y][nex.x][nex.by][nex.bx] = nex.t;
	  Q.push(nex);
	}
      }
    }

  }

  int ans = INF;
  for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++) ans = min(ans,T[i][j][gy][gx]);

  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;
}

int main(){
  
  while(cin >> w >> h && w+h){
    init();
    input();
    solve();
  }
  return 0;
}

Measured memory_bytes: 1216
import fractions

A,B,C,D = list(map(int, input().split()))

C_div = B//C - (A-1)//C
D_div = B//D - (A-1)//D
CandD = int(C*D/fractions.gcd(C, D))
CandD_div = B//CandD - (A-1)//CandD

print(B-(A-1)-C_div-D_div+CandD_div)


Measured memory_bytes: 5048
//package Test;

import java.util.*;

public class Main {

    static class Solution {

        void solve(int n){
            // N: 0-9, include 0 and 9
            // mod: 1000000007
            // dp[i][j][k]:
            // j==> 0: 0, 1: 9, 2: other
            // k==> 0: null, 1: 0, 2: 9, 3: 0 && 9
            int mod = 1000000007;
            int[][] dp = new int[n][4];

            dp[0][1] = 1;
            dp[0][2] = 1;
            dp[0][0] = 8;
            for(int i = 1; i < n; i++) {
                for (int j = 0; j < 10; j++) {
                    for (int k = 0; k < 4; k++) {
                        int bit = 0;
                        if (j == 0) bit = 1;
                        else if (j == 9) bit = 2;
                        dp[i][k | bit] = (dp[i][k | bit] + dp[i - 1][k]) % mod;
                    }
                }
            }

            System.out.println(dp[n-1][3]);
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Solution solution = new Solution();
        solution.solve(n);

    }
}


Measured memory_bytes: 85296
#include<iostream>
using namespace std;
string s;
int ans,n,cnt[26];
main(){
  cin>>n>>s;
  for(int i=1;i<n;i++){
    for(int j=0;j<26;j++)cnt[j]=0;
    for(int j=0;j<i;j++)cnt[s[j]-'a']++;
    int now=0;
    for(int j=i;j<n;j++)if(cnt[s[j]-'a'])now++,cnt[s[j]-'a']=0;
    ans=ans<now?now:ans;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>

using namespace std;

template<typename T>void read(T&x){x=0;int fl=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')
fl=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}x*=fl;}
template<typename T,typename...Args>inline void read(T&t,Args&...args){read(t);read(args...);}

typedef long long LL;

int n;
char s[105];

bool check(int l, int r){
    for(int i = l; i <= r; i++)
        if(s[i] != s[r - i + l])
            return false;
    return true;
}

int main(){
    scanf("%s", s+1);
    n = strlen(s+1);
    if(check(1, n) && check(1, (n - 1) / 2) && check((n + 3) / 2, n))
        puts("Yes");
    else    puts("No");
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx")
#include <bits/stdc++.h>

constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


int main() {
	int N;
	cin >> N;
	vector<int> H(N), H2;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	H2.push_back(H[0]);
	for (int i = 1; i < N; i++) {
		if (H[i - 1] != H[i])H2.push_back(H[i]);
	}
	for (int i = 1; i < H2.size(); i++) {
		if (H2[i - 1] > H2[i])H2[i-1]--;
	}
	for (int i = 1; i < H2.size(); i++) {
		if (H2[i - 1] > H2[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 1276
#include<stdio.h>
int main(void)
{
  int n,k;
  scanf("%d%d",&n,&k);
  int c=0,h[n],i;
  for(i=0;i<n;i++){
    scanf("%d",&h[i]);
    if(h[i]>=k)
      c++;
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

template<class T> struct MinCostFlow {
  struct Edge {
    int to, rev;
    T cap, cost;
    Edge () {}
    Edge (int _to, T _cap, T _cost, int _rev) :
      to(_to), cap(_cap), cost(_cost), rev(_rev) {}
  };
  const T INF = numeric_limits<T>::max() / 2;
  int N;
  vector< vector<Edge> > G;
  vector<T> h;
  vector<T> dist;
  vector<int> prevv, preve;
  MinCostFlow (int n) : N(n), G(n), h(n), dist(n), prevv(n), preve(n) {}

  void add_edge(int from, int to, T cap, T cost) {
    G[from].push_back(Edge(to,cap,cost,G[to].size()));
    G[to].push_back(Edge(from,0,-cost,G[from].size()-1));
  }

  T get_min(int s, int t, T f) {
    T ret = 0;
    for (int i=0; i<N; i++) h[i] = 0;
    while (f > 0) {
      priority_queue< pair<T,int>, vector< pair<T,int> >, greater< pair<T,int> > > que;
      for (int i=0; i<N; i++) dist[i] = INF;
      dist[s] = 0;
      que.push(make_pair(0,s));
      while (que.size() != 0) {
        pair<int,int> p = que.top();
        que.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;
        for (int i=0; i<G[v].size(); i++) {
          Edge &e = G[v][i];
          if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
            dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
            prevv[e.to] = v;
            preve[e.to] = i;
            que.push(make_pair(dist[e.to], e.to));
          }
        }
      }
      if (dist[t] == INF) {
        return -1;
      }
      for (int v=0; v<N; v++) h[v] += dist[v];
      int d = f;
      for (int v=t; v!=s; v=prevv[v]) {
        d = min(d,G[prevv[v]][preve[v]].cap);
      }
      f -= d;
      ret += d * h[t];
      for (int v=t; v!=s; v=prevv[v]) {
        Edge &e = G[prevv[v]][preve[v]];
        e.cap -= d;
        G[v][e.rev].cap += d;
      }
    }
    return ret;
  }
};

int main() {

  int V,E,F;
  cin >> V >> E >> F;
  MinCostFlow<int> inst(110);

  REP(i,E) {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    inst.add_edge(a,b,c,d);
  }

  cout << inst.get_min(0,V-1,F) << endl;

  return 0;
}

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



public class Main
{	
	public static void main(String args[]) throws IOException
	{
		FastScanner fs = new FastScanner();
			int n = fs.nextInt(),count=0;
			for(int i=0; i<n; i++)
			{
				int s = fs.nextInt();
				if((i+1)*s%2 == 1)
					count++;
			}
			System.out.println(count);
	}

}
class FastScanner
{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer str = new StringTokenizer("");
	
	String next() throws IOException
	{
		while(!str.hasMoreTokens())
			str = new StringTokenizer(br.readLine());
		
		return str.nextToken();
	}
	
	int nextInt() throws IOException
	{
		return Integer.parseInt(next());
	}
	
	float nextfloat() throws IOException
	{
		return Float.parseFloat(next());
	}
	
	double nextDouble() throws IOException
	{
		return Double.parseDouble(next());
	}
	long nextLong() throws IOException
	{
		return Long.parseLong(next());
	}
	int[] arrayIn(int n) throws IOException
	{
		int arr[] = new int[n];
		for(int i=0; i<n; i++)
		{
			arr[i] = nextInt();
		}
		return arr;
	}
}



	

Measured memory_bytes: 32792
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <bits/stdc++.h>

#define REP(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;
using ll = long long;

/**
 * main
 */
int main () {
  string S;
  cin >> S;

  if (
       S == "hi"
    || S == "hihi"
    || S == "hihihi"
    || S == "hihihihi"
    || S == "hihihihihi"
    || S == "hihihihihihi"
    || S == "hihihihihihihi"
    || S == "hihihihihihihihi"
    || S == "hihihihihihihihihi"
    || S == "hihihihihihihihihihi"
  ) printf("Yes\n");
  else printf("No\n");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	c<<=1;
	long long ans=0;
	if(c>(a+b)){
		ans=d*a+e*b;
	}else {
		int p=min(d,e);
		ans+=p*c;
		d-=p;e-=p;
		if(d!=0){ans+=min(c,a)*d;}
		if(e!=0){ans+=min(c,b)*e;}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ar array
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	int h, n;
	cin >> h >> n;
	int a[n];
	int s=0;
	for(int i=0; i<n; ++i) {
		cin >> a[i];
		s+=a[i];
	}
	cout << (s>=h?"Yes":"No");
}

Measured memory_bytes: 640
N, M, X, Y = map(int, input().split())
x = [int(x) for x in input().split()]
y = [int(x) for x in input().split()]
_X = max(X, max(x))
_Y = min(Y, min(y))
if _X < _Y:
    print("No War")
else:
    print("War")


Measured memory_bytes: 2940
s = input().rstrip().split()
h = int(s[0])
w = int(s[1])

table = []

for i in range(h):
  t = input()
  line = list(t)
  table.append(line)

flg = 0

h_edge = h-1
w_edge = w-1

for i in range(h):
  for j in range(w):
    if(table[i][j] == "#"):
      table[i][j] == "/"
      if(i == 0 and j == 0):
        if(table[i][j+1] == "." and table[i+1][j] == "."):
          flg = 1
      elif(i == 0 and j != w_edge):
        if(table[i][j+1] == "." and table[i+1][j] == "." and table[i][j-1] == "."):
          flg = 1
      elif(j == 0 and i != h_edge):
        if(table[i][j+1] == "." and table[i+1][j] == "." and table[i-1][j] == "."):
          flg = 1
      elif(i == h_edge and j == w_edge):
        if(table[i-1][j] == "." and table[i][j-1] == "."):
          flg = 1
      elif(i == h_edge):
        if(table[i][j+1] == "." and table[i][j-1] == "." and table[i-1][j] == "."):
          flg = 1
      elif(j == w_edge):
        if(table[i+1][j] == "." and table[i][j-1] == "." and table[i-1][j] == "."):
          flg = 1
      else:
        if(table[i][j+1] == "." and table[i+1][j] == "." and table[i][j-1] == "." and table[i-1][j] == "."):
          flg = 1
      if(flg == 1):
        break
  else:
    continue
  break

if(flg==0):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3192
N = int(input())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
count2 = 0
for i in range(N-1,-1,-1):
    count = B[i]*((A[i]+count2-1)//B[i] + 1) - A[i]-count2
    count2 += count
print(count2)

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

int main() {
  string s;
  cin >> s;
  int price = 700;
    if (s[0] == 'o') price += 100;
    if (s[1] == 'o') price += 100;
    if (s[2] == 'o') price += 100;
  
  cout << price << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! { n:usize, a:[usize;n], }
    let mut ans = 1;
    let mut cur = 1;
    for x in a {
        if x == 1 {
            cur += 1;
        } else {
            ans = std::cmp::max(ans, cur);
            cur = 1;
        }
    }
    ans = std::cmp::max(ans, cur);
    println!("{}", ans);
}



Measured memory_bytes: 5036
n=int(input())
*v,=map(int,input().split())
a=[[0,i]for i in range(10**5+1)]
b=[[0,i]for i in range(10**5+1)]
for t,u in zip(sorted(v[::2]),sorted(v[1::2])):a[t][0]+=1;b[u][0]+=1
a.sort(reverse=1)
b.sort(reverse=1)
print(n-a[0][0]-[max(a[1][0],b[1][0]),b[0][0]][a[0][1]!=b[0][1]])

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

using namespace std;

int main(){

  int n, k;
  cin >> n >> k;

  int p = 1;

  p *= k;

  for (int i = 1; i < n; i++){
    p *= (k - 1);
  }

  cout << p << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
	int h, w;
	cin >> h >> w;
	vector<string> F(h);
	for (int i = 0; i < h; ++i) cin >> F[i];
	vector<vector<int> > 
		L(h, vector<int>(w)), R(h, vector<int>(w)),
		D(h, vector<int>(w)), U(h, vector<int>(w));

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (F[i][j] == '#') L[i][j] = 0;
			else if (j == 0) L[i][j] = 1;
			else if (j > 0) L[i][j] = L[i][j - 1] + 1;
		}
	}
	for (int i = 0; i < h; ++i) {
		for (int j = w - 1; j >= 0; --j) {
			if (F[i][j] == '#') R[i][j] = 0;
			else if (j == w - 1) R[i][j] = 1;
			else if (j < w - 1) R[i][j] = R[i][j + 1] + 1;
		}
	}
	for (int j = 0; j < w; ++j) {
		for (int i = 0; i < h; ++i) {
			if (F[i][j] == '#') D[i][j] = 0;
			else if (i == 0) D[i][j] = 1;
			else if (i > 0) D[i][j] = D[i - 1][j] + 1;
		}
	}
	for (int j = 0; j < w; ++j) {
		for (int i = h - 1; i >= 0; --i) {
			if (F[i][j] == '#') U[i][j] = 0;
			else if (i == h - 1) U[i][j] = 1;
			else if (i < h - 1) U[i][j] = U[i + 1][j] + 1;
		}
	}
	int ans = 0;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			ans = max(ans, L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3);
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main() {
   int a , b , c;
   cin >> a >> b >> c;
   if(a == b){
       cout<<c;
   }
   if(a == c){
       cout<<b;
   }
   if(c == b){
       cout<<a;
   }
   
}

Measured memory_bytes: 256
#include<atcoder/all>
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;
using namespace atcoder;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main(){
    int t;
    cin >> t;
    REP(i,t){
        int n,m,a,b;
        cin >> n >> m >> a >> b;
        cout << floor_sum(n,m,a,b) << endl;
    }

    



    return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <string>

int main()
{
    using namespace std;
    
    long int a, b, x;
    cin >> a >> b >> x;

    long int cnt = b/x;
    if(a==0)
        cnt += 1;
    else
        cnt -= (a-1)/x;
    cout << cnt << endl;
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    if (s == "Sunny") {
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy") {
        cout << "Rainy" << endl;
    }
    else {
        cout << "Sunny" << endl;
    }
    return 0;
}



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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

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

    int N; cin >>N;
    vector<ll> a(3*N); cin >> a;

    sort(ALL(a), greater<int>());    

    ll ans = 0;
    for (int i=1; i <2*N; i+=2) {
       ans +=a[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <cmath>
using namespace std;

int main() {
  float a, b;
  int mean = 0;

  cin >> a >> b;


  cout << int(round((a + b) / 2)) << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define mk make_pair
#define sz size
#define inf 1e9+5
 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n,t;
    string str;
    cin>>n>>str;
    for(ll i=0;i<str.length();i++){
        int k=str[i]-'A';
        k = (k+n)%26;
        // cout<<k<<" ";
        str[i]='A' +k;
    }
    cout<<str;


    return 0;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

// Copied my code from a similar problem in ECPC 2018.
const int N = 1000001;
const int MOD = 998244353;

int power(int b, int p) {
  if (p == 0) return 1;
  int tmp = power(b, p / 2);
  tmp = 1LL * tmp * tmp % MOD;
  if (p & 1) {
    tmp = 1LL * tmp * b % MOD;
  }
  return tmp;
}

int modInv(int x) {
  return power(x, MOD - 2);
}

int mod_inv[N];

int multiples_sum[N]; // multiples[i] contains the sum of the elements in the array that are multiples of i.
int sumOfPairwiseProductsOfMultiples[N];

vector<int> divisors[N]; // divisors[i] contains the divisors of i. To be built in pre-processing.

int cnt[N];

void buildMultiples(const vector<int>& v) {
  for (int i = 1; i < N; ++i) {
    if (cnt[i] == 0) continue;
    for (int d : divisors[i]) {
      multiples_sum[d] = (multiples_sum[d] + 1LL * i * cnt[i]) % MOD;
    }
  }
}

void buildSumOfPairwiseProducts() {
  for (int d = 1; d < N; ++d) {
    sumOfPairwiseProductsOfMultiples[d] = 1LL * multiples_sum[d]
      * multiples_sum[d] % MOD;
  }
}

void buildModInv() {
  for (int i = 1; i < N; ++i) {
    mod_inv[i] = modInv(i);
  }
}

void preprocess() {
  for (int i = 1; i < N; ++i) {
    for (int j = i; j < N; j += i) {
      divisors[j].push_back(i);
    }
  }
  buildModInv();
}

int solve(const vector<int>& v) {
  buildMultiples(v);
  buildSumOfPairwiseProducts();
  int res = 0;

  for (int d = N - 1; d >= 1; --d) {
    res = (res + 1LL * sumOfPairwiseProductsOfMultiples[d] * mod_inv[d]) % MOD;
    for (int j : divisors[d]) {
      sumOfPairwiseProductsOfMultiples[j] = (sumOfPairwiseProductsOfMultiples[j]
        + MOD - sumOfPairwiseProductsOfMultiples[d]) % MOD;
    }
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  preprocess();
  int n;
  cin >> n;

  vector<int> v(n);
  for (int& x : v) {
    cin >> x;
    ++cnt[x];
  }

  int res = solve(v);
  for (int x : v) {
    res = (res - x + MOD) % MOD;
  }
  res = 1LL * res * mod_inv[2] % MOD;
  cout << res << endl;

}



Measured memory_bytes: 131200
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
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; }



int main(int argc, char const *argv[]) {
  int n,x,t;
  cin >> n >> x >> t;
  cout << (n + x - 1) / x * t << endl;
  return 0;
}

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

using namespace std;
#define BUF (1000)
#define ll long long 
#define MX (1000000000000000000)


ll n;
ll e5 = 0;

ll find_e5(void){
	ll ret = 1;
	ll tmp = 1;
	while(MX>tmp){
		tmp *=5;
		ret++;
	}
	return ret;
}

int main(void){
	cin >> n;
	if(n%2 == 1){
		cout << 0 << endl;
		return 0;
	}

	e5 = find_e5();
	//cout << e5 << endl;

	ll md = 1;
	ll ans = 0;
	for(int i=0;i<e5;i++){
		md*=5;
		ans += (n/md)/2;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split(' '))
if M == 0:
    if N == 1:
        print(0)
    else:
        print('1', '0' * (N - 1), sep='')
else:
    is_end = False
    rst = [''] * N
    for i in range(M):
        s, c = input().split(' ')
        idx = int(s) - 1
        if idx == 0 and N != 1 and c == '0':
            print(-1)
            is_end = True
            break
        elif rst[idx] == '':
            rst[idx] = c
        elif rst[idx] != c:
            print(-1)
            is_end = True
            break
    if not is_end:
        for i, j in enumerate(rst):
            if i == 0 and j == '':
                print('1', end='')
            elif j == '':
                print('0', end='')
            else:
                print(j, end='')

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

using namespace std;

template<typename Edge> class Graph {
protected:
  vector<vector<Edge>> edges;

public:
  Graph(int n = 0) : edges(n) {}
  
  void addEdge(const Edge& edge) {
    if (int(edges.size()) <= max(edge.from, edge.to)) edges.resize(max(edge.from, edge.to) + 1);
    edges[edge.from].emplace_back(edge);
  }
};

template<typename Edge> class ShortestPath : public Graph<Edge> {
private:
  typedef __typeof(Edge::cost) Cost;

  struct State {
    int pos;
    Cost cost;
    bool operator<(const State& state) const {return cost > state.cost;}
  };

public:
  const Cost INF;

  vector<Cost> dist;

  ShortestPath(const Graph<Edge>& graph) : Graph<Edge>(graph), INF(numeric_limits<Cost>::max()) {}
  
  void run (int from) {
    priority_queue<State> que;
    que.push((State){from, 0});
    dist.resize(this->edges.size(), INF);
    
    while (!que.empty()) {
      State now = que.top();
      que.pop();
      if (dist[now.pos] <= now.cost) continue;
      dist[now.pos] = now.cost;
      for (const Edge& edge : this->edges[now.pos]) {
        if (dist[edge.to] < now.cost + edge.cost) continue;
        que.push((State){edge.to, now.cost + edge.cost});
      }
    }
  }
};

struct Edge {
  int from, to, cost;
};

int main() {
  int v, e, r;
  cin >> v >> e >> r;
  Graph<Edge> graph(v);
  for (int i = 0; i < e; ++i) {
    int s, t, d;
    cin >> s >> t >> d;
    graph.addEdge((Edge){s, t, d});
  }
  ShortestPath<Edge> shortestPath = graph;
  shortestPath.run(r);
  for (int c : shortestPath.dist) {
    if (c != shortestPath.INF) cout << c << endl;
    else cout << "INF" << endl;
  }
}

Measured memory_bytes: 24032
# C - Sequence

import numpy as np

n = int(input())
original_a = list(map(int, input().split()))

def ope_sequence(a, plus_flg):
    a = a.copy()
    output = 0
    
    if plus_flg == 1: # 偶数項で累積和を正とする
        c = 0 # 累積和
        for idx in range(n):
            c += a[idx]
            if idx % 2 == 0 and c <= 0:
                a[idx] += 1-c # 累積和が+1となるように操作
                output += abs(1-c)
                c = 1
            elif idx % 2 == 1 and c >= 0:
                a[idx] += -1-c # 累積和が-1となるように操作
                output += abs(-1-c)
                c = -1
                
    else: # 偶数項で累積和を負とする
        c = 0
        for idx in range(n):
            c += a[idx]
            if idx % 2 == 0 and c >= 0:
                a[idx] += -1-c 
                output += abs(-1-c)
                c = -1
            elif idx % 2 == 1 and c <= 0:
                a[idx] += 1-c 
                output += abs(1-c)
                c = 1
    
    return output

print(min(ope_sequence(original_a,1), ope_sequence(original_a,-1)))

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

using namespace std;

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

int main()
{
  int n,a,b,c,d;
  string s;
  
  cin >> n >> a >> b >> c >> d;
  cin >> s;
  /*
  cout << n << endl;
  cout << a << endl;
  cout << b << endl;
  cout << c << endl;
  cout << d << endl;
  cout << s << endl;
  */
  bool check1 = true;
  bool check2 = false;
  int m = max(c, d);
  int m2 = min(c, d);
  
  for (int i=0;i<m;++i) {
    if (a <= i && i < m-1) {
      if (s[i] == '#' && s[i+1] == '#') {
      	check1 = false;
      	break;
	  }
    }
    
    if (d < c) {
      if (b-2 <= i && i < m2-1 ) {
        if (s[i] == '.' && s[i+1] == '.' && s[i+2] == '.') {
        	check2 = true;
	    }
      }
    }
  }
  
  string ans = "Yes";
  if (!check1)
    ans = "No";
  if (d < c && !check2)
    ans = "No";
  
  cout << ans << endl;

  return 0;
}


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

using namespace std;

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


int main()
{
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  ll tmp1 = a * x + b * y;
  ll tmp2 = max(x, y) * 2 * c;
  ll tmp3 = min(x, y) * 2 * c;
  if (x > y) {
    tmp3 += ((max(x, y)-min(x, y)) * a);
  }else{
    tmp3 += ((max(x, y)-min(x, y)) * b);
  }
  tmp1 = min(tmp1, tmp2);
  cout << min(tmp1, tmp3) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.*;

public class Main {
    public static void main(String[] args){
        ABC160B();
    }
    private static void ABC160B() {
        // no comment, no error check
        final int INPUT_LINES_CNT = 1;
        final String DATA_SPLIT_SPACE = " ";

        ArrayList<String> inputLines = getStdInMultiLines(INPUT_LINES_CNT);

        if (inputLines.size() == 0) {
            System.out.println(0);
            return;
        }

        String outputStr;
        int point = 0;
        try {
            List<String> inputLineList= 
            Arrays.asList((inputLines.get(0)).split(DATA_SPLIT_SPACE));

            int money = Integer.valueOf(inputLineList.get(0));
            int remain = money;

            point = point + (remain / 500) * 1000;
            remain = remain % 500;
            point = point + (remain / 5) * 5;
            outputStr = String.valueOf(point); 
        }
        catch (Exception ex) {
            outputStr = "0";
        }

        System.out.println(outputStr);
        return;
    }

    private static int getStdInNum() {
        String line1 = getStdInSingleLine();
        if (isNumber(line1)) {
            return Integer.parseInt(line1);
        }
        return 0;
    }

    private static ArrayList<String> getStdInMultiLines() {
        int cnt = 0; 
        int max = 0;

        Scanner cin = new Scanner(System.in);
        ArrayList<String> list = new ArrayList<String>();
        for (;cin.hasNext();) {
            list.add(cin.nextLine());
            if (cnt++ == 0) {
                max = Integer.parseInt((list.get(0)).split(" ")[0]);
            }
            else if (cnt == max + 1) {
                break;
            }
        }
        cin.close();
        return list;
    }
    private static ArrayList<String> getStdInMultiLines(int inputLinesCnt) {
        int cnt = 0; 

        Scanner cin = new Scanner(System.in);
        ArrayList<String> list = new ArrayList<String>();
        for (;cin.hasNext();) {
            list.add(cin.nextLine());
            if (++cnt == inputLinesCnt) {
                break;
            }
        }
        cin.close();
        return list;
    }

    private static String getStdInSingleLine() {
        Scanner cin = new Scanner(System.in);

        for (;cin.hasNext();) {
            cin.close();
            return cin.nextLine();
        }

        cin.close();
        return "";
    }

    private static boolean isNumber(String val) {
        try {
            Integer.parseInt(val);
            return true;
        }
        catch (NumberFormatException nfex) {
            return false;
        }
    }

}


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

int n, x;
long long ans;
map<long long, int> mp;

int main(void) {
  scanf("%d", &n);
  long long s = 0;
  mp[0]++;
  for(int i = 1; i <= n; i++) {
    scanf("%d", &x);
    s += x;
    ans += mp[s];
    mp[s]++;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 12800
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <utility>
typedef long long ll;
using namespace std;
#define maxn 200000

int main()
{
    ll n,m;
   cin>>n>>m;
   if(max(n,m)-min(n,m)>=2)
   {
       printf("Alice\n");
   }
   else printf("Brown\n");
}





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <list>
#include <stack>
#include <set>
#include <algorithm>
#include <math.h>

using namespace std;

#define dump(x) cout << (x) << endl;
typedef long long Int;

Int mod = 1e9+7;
Int MOD = 998244353;

int main() {
    Int n;
    cin >> n;
    map<Int, Int> mp;
    for (Int i = 0; i < n; i++) {
        Int tmp;
        cin >> tmp;
        mp[tmp]++;
    }
    Int res = mp.size();
    Int x = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        x += itr->second-1;
    }
    dump(x%2 == 0 ? res : res-1);
    return 0;
}  

Measured memory_bytes: 6528
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, r;
  cin >> h >> r;
  if(h >= 0) cout << 1 << endl;
  else if(abs(h) == r) cout << 0 << endl;
  else if(h < 0) {
      if(abs(h) >= r) cout << -1 << endl;
      else cout << 1 << endl;
  }
}


Measured memory_bytes: 3148
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          string w = Input.ScanStr();
          Console.WriteLine(w.Substring(0,w.Length-8));
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    if(n == 1){
        cout << "Hello World" << endl;
        return 0;
    }else if(n == 2){
        int a,b;
        cin >> a >> b;
        cout << a+b << endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#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;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	vl RGBsum(3, 0);
	rep(i, N) {
		RGBsum[0] += (S[i] == 'R');
		RGBsum[1] += (S[i] == 'G');
		RGBsum[2] += (S[i] == 'B');
	}
	ll ans = 1;
	rep(i, 3)
		ans *= RGBsum[i];
	rep(i, N) {
		rep(diff, N) {
			int j = i + diff;
			int k = j + diff;
			if (k >= N)
				continue;
			if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i])
				ans--;
		}
	}


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

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

using namespace std;

const int N = 1e5 + 7;
int n;

int main() {
    std :: ios :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> p;
vector<ll>v;
ll arr[100001]={0};
int main()
{
    ll n,k,a,b,c,ans=0;
    cin >>n;
    for(ll i=0;i<n;i++)
    {
    	cin >> a;
    	arr[a]++;
        ans+=a;
    }
//   cout<<arr[1]<<endl;
    cin >> k;
    for(ll i=0;i<k;i++)
    {
        cin >>b>>c;
        arr[c]=arr[c]+arr[b];
//        cout<<arr[c]<<""<<arr[b];
        ans=ans-(arr[b]*b)+(arr[b]*c);
        arr[b]=0;
        cout << ans<<endl; 
    }
    return 0;
}


Measured memory_bytes: 4384
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-(a)) : (a))

typedef long long ll;

using namespace std;

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

	ll a, b, c;

	cin >> a >> b >> c;

	ll l = a * a + b * b + 2LL * a * b + c * c - 2LL * (a + b) * c;
	ll r = 4LL * a * b;

	if (l > r && c - a - b >= 0) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}

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

using ll = long long;

using namespace std;

int main() {
    int n;
    cin >> n;
    ll cnt[100010] = {0};
    ll sum = 0;
    for (int i=0, ai; i<n; i++) {
        cin >> ai;
        cnt[ai]++;
        sum += ai;
    }
    int q; cin >> q;
    for (int i=0, bi, ci; i<q; i++) {
        cin >> bi >> ci;
        sum += cnt[bi] * (ci - bi);
        cnt[ci] += cnt[bi];
        cnt[bi] = 0;
        cout << sum << '\n';
    }
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector <int> w(n);
    vector <int> wa(n);
    int wa2=0;
    rep(i,n){
        cin >> w[i];
        wa2+=w[i];
        wa[i]=wa2;
    }

    int j;
    rep(i,n){
        if(wa[i]>(wa2/2)){
            j=i;
            break;
        }
    }

    int ans;
    ans=min((wa2-2*wa[j-1]),wa[j]-(wa2-wa[j]));
    cout << ans << endl;
    

    return 0;
}

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

int main() {
  
  int P, Q, R;
  vector<int> pqr(3);
  cin >> pqr.at(0) >> pqr.at(1) >> pqr.at(2);
  
  sort(pqr.begin(), pqr.end());
  cout << pqr.at(0)+pqr.at(1) << endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	bool flag = false;
	for (const auto& num : n) {
		if (num == '7') {
			flag = true;
		}
	}
	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3596
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n,m,i,j,c=0;
    int a[100][100],b[1000];
    
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(j=0;j<m;j++){
        scanf("%d",&b[j]);
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            c+=a[i][j]*b[j];
        }
        printf("%d\n",c);
        c=0;
    }

    return 0;
}



Measured memory_bytes: 2100
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

a,b,c = LI()

if c <= a+b:
    print('No')
else:
    if 4*a*b < (c-a-b)**2:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 38384
[a, b, c] = list(map(int, input().split()))
k = int(input())
canhe = True
passOne = False
abk = 0
bck = 0
bc = b
cc = c
while True:
    if abk > k:
        canhe = False
        break
    if bc <= a:
        bc *= 2
        abk += 1
    else:
        passOne = True
        break
if passOne:
    while True:
        if bck > k-abk:
            canhe = False
            break
        if cc <= bc:
            cc *= 2
            bck += 1
        else:
            break
if canhe:
    print("Yes")
else:
    print("No")

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

LL gcd(LL a, LL b){
    if(b > a) return gcd(b, a);
    if(b == 0) return a;
    return gcd(b, a%b);
}

void solve(long long N, long long X, std::vector<long long> x){
    REP(i, N) x[i] = abs(x[i]-X);
    LL ans = x[0];
    REP1(i, N) {
        ans = gcd(ans, x[i]);
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    std::vector<long long> x(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
    }
    solve(N, X, std::move(x));
    return 0;
}


Measured memory_bytes: 1024