akhauriyash/Code-Regression huggingface dataset:
# agc003_a.py
S = input()
direct = [0]*4
for i in S:
    if i == "W":
        direct[0] = 1
    elif i == "E":
        direct[1] = 1
    elif i == "S":
        direct[2] = 1
    elif i == "N":
        direct[3] = 1
if direct[0] == direct[1] and direct[3] == direct[2]:
    print('Yes')
    exit()
print('No')


Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s:String = read();
    let t:String = read();

    if &s[..] == &t[0..s.len()] {
        println!("Yes");
    }else{
        println!("No");
    }

}


Measured memory_bytes: 2176
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		double b = sc.nextDouble();
        b*=500;
        int c = (int)b;
        long d = a*c;
		System.out.println(d/500);
	}
}


Measured memory_bytes: 36880
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<n+1;i++)
typedef vector<int> vec;
int main(){
  int n,k; cin>>n>>k;
  int dp[n+5];
  int h[n+5];
  rep(i,n) cin>>h[i];
  rep(i,n){
    if(i==1) dp[i]=0;
    else dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
    rep(x,k){if(i-x>0) dp[i]=min( dp[i], dp[i-x]+abs(h[i]-h[i-x]) );}
  }
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 1024
import math
from functools import reduce
import fractions

a = input()
a = int(a)

b = []
c = []

for i in range(1, a+1):
    for j in range(1, a+1):
        x = math.gcd(i, j)
        b.append(x)
for k in range(1, a+1):
    for l in b:
        y = math.gcd(k, l)
        c.append(y)
    
print(sum(c))

Measured memory_bytes: 72972
import sys

inf = int(1e12)

def shortestPath(graph, s):
    n = len(graph)
    dist = [inf for _ in range(n)]
    dist[s] = 0

    for i in range(n):
        for u in range(n):
            for v, cost in graph[u]:
                newDist = dist[u] + cost
                if dist[u] != inf and newDist < dist[v]:
                    if i == n - 1:
                        return None
                    dist[v] = newDist
    return dist

def main():
    v, e, s = map(int, input().split())
    
    graph = [[] for _ in range(v)]
    
    for i in range(e):
        a, b, cost = map(int, input().split())
        graph[a].append((b, cost))
            
    dist = shortestPath(graph, s)

    if not dist:
        print("NEGATIVE CYCLE")
    else:
        for d in dist:
            if d >= inf:
                print("INF")
            else:
                print(d)
main()

Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i = m;i < n;i++)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) REP(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define fi first
#define se second
const int inf = 1e9;

int a[101];
int main(){
	int n, m, x;
	scanf("%d%d%d", &n, &m, &x);
	rep(i,n)scanf("%d", &a[i]);
	int ans = 0;
	rep(i,n){
		ans += (m-1)/a[i]+1;
	}
	printf("%d\n", x+ans);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
V = input().split()
C = input().split()
cost = []
x = 0
for i in range(N):
    cost.append(int(V[int(i)]) - int(C[int(i)]))
for i in range(N):
    if cost[i] > 0:
        x = x + int(cost[i])
print(x)

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if((a+b) >= c){
    puts("Yes");
    return 0;
  }
  puts("No");
  return 0;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e18+5;

int a[405];
ll memo[405][405];
ll pref[405];

ll sum(int l, int r) {
	if (l == 0) return pref[r];
	return pref[r]-pref[l-1];
}

ll dp(int l, int r) {
	if (l == r) return 0;
	if (memo[l][r] != -1) return memo[l][r];
	ll minn = INF;
	for (int i=l ; i<r ; i++) {
		minn = min(minn, dp(l, i)+dp(i+1, r)+sum(l, r));
	}
	return memo[l][r] = minn;
}

int main() {
	memset(memo, -1, sizeof memo);
	int n;
	scanf("%d", &n);
	for (int i=0 ; i<n ; i++) {
		if (i) pref[i] = pref[i-1];
		scanf("%d", a+i);
		pref[i] += a[i];
	}
	printf("%lld\n", dp(0, n-1));
	return 0;
}

Measured memory_bytes: 5096
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

int main(int argc, char *argv[])
{
  std::string s, t;
  std::cin >> s >> t;
  auto t_itr = t.begin();
  size_t last_pos = 0;
  size_t t_pos = 0;
  size_t s_pos = 0;

  while (true)
  {
    size_t pos = s.find_first_of(t[t_pos], last_pos);
    if (pos == std::string::npos)
    {
      if (last_pos == 0)
      {
        std::cout << "-1" << std::endl;
        return 0;
      }
      s_pos += s.length() - last_pos;
      last_pos = 0;
    }
    else
    {
      s_pos += pos - last_pos;
      t_pos++;
      if (t_pos >= t.length())
      {
        std::cout << s_pos + 1 << std::endl;
        return 0;
      }
      s_pos++;
      last_pos = pos + 1;
      if (last_pos > s.length())
      {
        last_pos = 0;
      }
    }
  };
  return 0;
}


Measured memory_bytes: 640
n,m=map(int,input().split())
x=sorted(list(map(int,input().split())))
if m==1:
	dx=[0]
else:
	dx=sorted([x[i+1]-x[i] for i in range(m-1)],reverse=True)
if n==1:
	print(x[-1]-x[0])
else:
	print(x[-1]-x[0]-sum(dx[0:n-1]))

Measured memory_bytes: 13960
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using ll = long long;

template <typename T>
T min(T a, T b){
  return (a < b) ? a : b;
}

template <typename T>
class SegTree{
  static const int MAXN = 100010;
  T INF;
  int n;
  T A[MAXN*4];
  T time[MAXN*4];
  public:
  SegTree(int size, T INF): INF(INF){
    n = 1;
    while(n < size){
      n *= 2;
    }
    n *= 2;
    for(int i = 0; i < MAXN*4; i++) A[i] = INF;
    for(int i = 0; i < MAXN*4; i++) time[i] = 0;
  }

  void update(int a, int b, T v, T t){
    return _update(a, b, 0, 0, n, v, t);
  }

  void _update(int a, int b, int k, int l, int r, T v, T t){
    if(a >= r || b <= l){
      return;
    }
    if(l >= a && r <= b){
      A[k] = v;
      time[k] = t;
      return;
    }
    _update(a, b, 2*k + 1, l, (l+r)/2, v, t);
    _update(a, b, 2*k + 2, (l+r)/2, r, v, t);
  }

  T query(int _idx){
    int offset = n - 1;
    int idx = _idx + offset;
    T t = 0;
    T ans = INF;
    while(idx > 0){
      if(time[idx] >= t){
        ans = A[idx];
        t = time[idx];
      }
      idx = (idx-1)/2;
    }
    return ans;
  }
};

int main(void){
  int n, q; cin >> n >> q;
  SegTree<int> rmq(n, 0x7FFFFFFF);
  for(int loop = 0; loop < q; loop++){
    int com;
    cin >> com;
    if(com == 0){
      int x, y, v; cin >> x >> y >> v;
      rmq.update(x, y+1, v, loop+1);
    }else{
      int i; cin >> i;
      cout << rmq.query(i) << endl;
    }
  }
}



Measured memory_bytes: 6248
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
ans = 0
for i in range(1,n):
    if(i<4):
        ans += a[i-1]
    elif(i<6):
        ans += a[i-3]
    else:
        ans += a[i//2]
print(ans)

Measured memory_bytes: 31444
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////


int main() {

	ll A, B, C, D;
	cin >> A >> B >> C >> D;

	ll a[200] = {};

	for (int i = A + 1; i <= B; i++) { a[i]++; }
	for (int i = C + 1; i <= D; i++) { a[i]++; }

	ll ans = 0;

	repn(i, 199) {
		if (a[i] == 2) { ans++; }
	}

	cout << ans;


	system("PAUSE");

	

}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
void read(int& x){ scanf("%d",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back

ll inf = (1LL << 62);

struct mat {
	ll x[6][6];
	mat(){
		for(int i=0; i<6; ++i) for(int j=0; j<6; ++j) x[i][j]=-inf;
	}
	mat operator*(mat r){
		mat ret;
		for(int i=0; i<6; ++i) for(int j=0; j<6; ++j){
			for(int k=0; k<6; ++k){
				if(x[i][k]!=-inf && r.x[k][j]!=-inf)
					ret.x[i][j] = max(ret.x[i][j], x[i][k]+r.x[k][j]);
			}
		}
		return ret;
	}
};

int n;

mat mul;

mat pow(ll e){
	if(e == 0){
		mat ret; for(int i=0; i<6; ++i) ret.x[i][i]=0;
		return ret;
	}
	mat ret=pow(e/2);
	ret=ret*ret;
	if(e&1) ret=ret*mul;
	return ret;
}

int main()
{
    for(int i=1; i<=6; ++i){
		for(int j=1; j<=6; ++j){
			if(i+j != 7 && i!=j){
				mul.x[i-1][j-1] = i;
			}
		}
    }
    ll n;
    cin >> n;
    ll l=0, r=n*100;
    while(l+1 < r){
		mat tmp=pow((l+r)/2);
		ll x=-inf;
		for(int i=0; i<6; ++i) for(int j=0; j<6; ++j) x=max(x, tmp.x[i][j]);
		if(x >= n) r=(l+r)/2;
		else l=(l+r)/2;
    }
    cout << r;
    return 0;
}


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

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
    int N;
    string S;
    cin >> N >> S;
    
    int count = 0;
    while(true) {
        int idx = S.find("ABC");
        if (idx == string::npos){
            break;
        }
        S.erase(0, idx+3);
        count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 888
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

N, A, B, C = map(int,input().split())
l = [int(input()) for i in range(N)]
com = []
ans = float('inf')

for i in range(4**N):
    x = Base_10_to_n(i, 4)
    if '1' in x and '2' in x and '3' in x:
        x = x.zfill(N)
        idx = 0
        a = []
        b = []
        c = []
        for i in x:
            i = int(i)
            if i == 1:
                a.append(l[idx])
            elif i == 2:
                b.append(l[idx])
            elif i == 3:
                c.append(l[idx])
            idx += 1
        MP = (len(a)+len(b)+len(c)-3) * 10
        MP += abs(sum(a)-A) + abs(sum(b)-B) + abs(sum(c)-C)
        ans = min(ans, MP)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iomanip>
#include <cstdlib>
// #include <fstream>
 
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; }
 
const long long mod = 1e9 + 7;
 
int main()
{
    int n, a, b; std::cin >> n >> a >> b;
    std::string s; std::cin >> s;
    int cnt=0, cntb=0;
    for(int i=0; i<n; i++)
    {
        if(cnt<a+b)
        {
            if(s[i]=='a')
            {
                cnt++;
                std::cout << "Yes\n";
                continue;   
            }            
            else if(s[i]=='b' && cntb<b)
            {
                cnt++;
                cntb++;
                std::cout << "Yes\n";
                continue;
            }
        }
        
        std::cout << "No\n";
    }
    
    return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin>>p.at(i);
    p.at(i)--;
  }

  bool flag=false;
  int ans=0;
  for(int i=0;i<N;i++){
    if(flag){
      flag=false;
      continue;
    }
    if(i==p.at(i)){
      ans++;
      flag=true;
    }else{
      flag=false;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    long double sum=0;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        long double sy;
        string si;
        cin>>sy>>si;
        if(si=="BTC")sy=sy*380000.0;
        sum+=sy;
    }
    cout<<fixed<<setprecision(6)<<sum<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

vector<ll> pate(50 + 1);
vector<ll> all(50 + 1);

ll dfs(int _n, ll _x) {// _nレベル、下から_x枚
	if (_n == 0) return _x ? 1 : 0;
	if (_x == 1) return 0;
	else if (_x <= 1 + all[_n - 1]) return dfs(_n - 1, _x - 1);
	else if (_x == 2 + all[_n - 1]) return pate[_n - 1] + 1;
	else if (_x <= 2 + all[_n - 1] * 2) return pate[_n - 1] + 1 + dfs(_n - 1, _x - 2 - all[_n - 1]);
	else if (_x == 3 + all[_n - 1] * 2) return 1 + pate[_n - 1] * 2;
	return 0;
}

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

	ll n;
	cin >> n;
	ll x;
	cin >> x;

	// パティの枚数
	// 下から食べる
	pate[0] = 1;
	all[0] = 1;
	rep(i, n){
		pate[i + 1] = 1 + 2 * pate[i];
		all[i + 1] = 3 + 2 * all[i];
	}

	ll ans = dfs(n, x);
	cout << ans << endl;;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		
		int n = sc.nextInt();
		
		int res =1;
		for(int i = 0;i<3;i++) {
			res *= n;
		}
		System.out.println(res);
	}
}


Measured memory_bytes: 23380
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int sum = n / 100;
    int num = n % 100;
    int k = num /5;
    int k2 = num % 5;
    if(k2)
        k++;
    if(k > sum)
        cout << '0' << endl;
    else
        cout << '1' << endl;
    return 0;
}

Measured memory_bytes: 256
int Balance(int N) {

/*N????????§?????£????????????????????????
 * ?????????0????????°?????§?????£????????§?????°
 * ????????????????????°???????????????????????§?????£????????§?????°
 * ????????????????????°???????????????????????§?????£????????§?????°
	*/

	int C;

	if(N==1||N==0)
		C = 0;

	else if(N%3==0)
		C = Balance(N/3) + 1;

	else if(N%3==1)
		C = Balance((N+2)/3) + 1;

	else if(N%3==2)
		C = Balance((N+1)/3) + 1;

	return C;
}


int main() {

	int N; //??\??????
	int Answer; //??????

	scanf("%d",&N);

	Answer = Balance(N); //?????????????´?

	printf("%d\n",Answer); //??????
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int A, B; cin >> A >> B;
  int ans = max(A, B);
  if (A > B) A--;
  else B--;

  ans += max(A, B);

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	int N;
	get(N);

	std::vector<LLONG> fn(N + 1, 0);
	for (int x = 1; x * x <= N; x++) {
		for (int y = 1; (x * x) + (y * y) <= N; y++) {
			for (int z = 1; ((x * x) + (y * y) + (z * z) + x * y + y * z + z * x) <= N; z++) {
				LLONG n = (x * x) + (y * y) + (z * z) + x * y + y * z + z * x;
				fn[n]++;
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		printf("%lld\n", fn[i]);
	}
}


Measured memory_bytes: 3676
A=int(input())
B=int(input())
C=int(input())
X=int(input())
count=0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if 500*i+100*j+50*k==X:
        count+=1
print(count)

Measured memory_bytes: 3064
def string_to_complex(s):
    a, b, c, d = map(int, s.split())
    return (a + b * 1j, c + d * 1j)

def dot(c1, c2):
    return c1.real * c2.real + c1.imag * c2.imag

def cross(c1, c2):
    return c1.real * c2.imag - c1.imag * c2.real

def cross_point(p1, p2, p3, p4):
    crs1 = cross(p2 - p1, p3 - p1)
    crs2 = cross(p2 - p1, p4 - p1)
    if crs1 == 0 and crs2 == 0:
        if p1 == p3 or p1 == p4:
            return p1
        elif p2 == p3 or p2 == p4:
            return p2
        else:
            return None
    crs3 = cross(p4 - p3, p1 - p3)
    crs4 = cross(p4 - p3, p2 - p3)
    if crs1 * crs2 <= 0 and crs3 * crs4 <= 0:
        base = p4 - p3
        hypo1 = p1 - p3
        hypo2 = p2 - p3
        d1 = abs(cross(base, hypo1)) / abs(base)
        d2 = abs(cross(base, hypo2)) / abs(base)
        return p1 + d1 / (d1 + d2) * (p2 - p1)
    else:
        return None

def contain(polygon):
    flag = False
    for a, b in zip(polygon[0:], polygon[1:] + [polygon[0]]):
        if a.imag > b.imag:
            a, b = b, a
        if a.imag <= 0 and b.imag > 0 and cross(a, b) > 0:
            flag = not flag
    return flag

def solve():
    def dfs_contain(goal, edges, cross_points):
        cur_edge = edges[-1]
        for next_edge, next_cp in adj_edge[cur_edge]:
            if next_edge == goal:
                if contain(cross_points + [next_cp]):
                    break
            elif next_edge not in edges and DP[next_edge]:
                edges.append(next_edge)
                cross_points.append(next_cp)
                if dfs_contain(goal, edges, cross_points):
                    break
                e = edges.pop()
                DP[e] = False
                cross_points.pop()
        else:
            return False
        return True
            
    from sys import stdin
    lines = stdin.readlines()
    
    from itertools import combinations
    
    while True:
        n = int(lines[0])
        if n == 0:
            break
        
        edges = enumerate(map(string_to_complex, lines[1:1+n]))
        adj_edge = [[] for i in range(n)]
        
        for e1, e2 in combinations(edges, 2):
            n1, t1 = e1
            n2, t2 = e2
            cp = cross_point(*t1, *t2)
            if cp:
                adj_edge[n1].append((n2, cp))
                adj_edge[n2].append((n1, cp))
        
        flag = True
        while flag:
            for i, ae in enumerate(adj_edge):
                if len(ae) == 1:
                    ne, cp = ae.pop()
                    adj_edge[ne].remove((i, cp))
                    break
            else:
                flag = False
        
        for e in range(n):
            DP = [False] * e + [True] * (n - e)
            if dfs_contain(e, [e], []):
                print('yes')
                break
        else:
            print('no')
        
        del lines[:1+n]

solve()


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

using i64 = long long;
const i64 LLINF = (1LL << 60);

int N;
i64 A[200005];
i64 suml[200005] = {};
i64 sumr[200005] = {};
int main()
{

    cin >> N;
    for ( int i = 0; i < N; i++ ) { 
        cin >> A[i];
        if ( i > 0 ) suml[i] = suml[i - 1] + A[i];
        else suml[i] = A[i];
    }
    i64 minv = LLINF;
    for ( int i = N - 1; i >= 0; i-- ) {
        if ( i < N - 1 ) {
            sumr[i] = sumr[i + 1] + A[i];
            minv = min(minv, llabs(suml[i] - sumr[i + 1]));
        } else {
            sumr[i] = A[i];
        }
    }

    cout << minv << endl;

    return ( 0 );
}


Measured memory_bytes: 4992
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) (a*a)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0])cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            int iL = int.Parse(sS[1]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<ClsApl> lstApl = new List<ClsApl>();
            for (int i = 1; i <= iN; i++)
            {
                ClsApl oneUsr = new ClsApl();
                oneUsr.iX = i - 1;
                oneUsr.iY = iL + i - 1;
                oneUsr.iZ = Math.Abs(oneUsr.iY);
                lstApl.Add(oneUsr);
            }
            lstApl.Sort(delegate (ClsApl mca1, ClsApl mca2) { return (int)(mca1.iZ - mca2.iZ); });      // iZの昇順
            lstApl.RemoveAt(0);
            int iOut = lstApl.Sum(x => x.iY);

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

        private class ClsApl
        {
            public int iX { get; set; }         // No
            public int iY { get; set; }         // 味
            public int iZ { get; set; }         // 味絶対値
        }

}


Measured memory_bytes: 11732
/*** 𝕒𝕜𝕤𝕙𝕒𝕪𝕜𝕦𝕞𝕒𝕣𝟡𝟡 ***/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=1e6+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
    ll n,i,j,ans=0;
    cin>>n;
    string s;
    cin>>s;
    ll r=0,g=0,b=0;
    f(i,1,n)
    {
        if(s[i]=='R')
            r++;
        else if(s[i]=='G')
            g++;
        else
            b++;
    }
    f(i,1,n-1)
    {
        if(s[i]=='R')
        {
            r--;
            f(j,0,i)
            {
                if(s[j]=='G')
                {
                    ans+=b;
                    if(i+(i-j)<n && s[i+i-j]=='B')
                        ans--;
                }
                if(s[j]=='B')
                {
                    ans+=g;
                    if(i+(i-j)<n && s[i+i-j]=='G')
                        ans--;
                }
            }
        }
        else if(s[i]=='G')
        {
            g--;
            f(j,0,i)
            {
                if(s[j]=='R')
                {
                    ans+=b;
                    if(i+(i-j)<n && s[i+i-j]=='B')
                        ans--;
                }
                if(s[j]=='B')
                {
                    ans+=r;
                    if(i+(i-j)<n && s[i+i-j]=='R')
                        ans--;
                }
            }
        }
        else
        {
            b--;
            f(j,0,i)
            {
                if(s[j]=='G')
                {
                    ans+=r;
                    if(i+(i-j)<n && s[i+i-j]=='R')
                        ans--;
                }
                if(s[j]=='R')
                {
                    ans+=g;
                    if(i+(i-j)<n && s[i+i-j]=='G')
                        ans--;
                }
            }
        }
    }
    cout<<ans<<'\n';

}

int main()
{
    IOS();
    #ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("output.txt","w",stdout);
    #endif
    int tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Measured memory_bytes: 3636
//https://atcoder.jp/contests/dp/tasks/dp_e
//shauryakr
#include<bits/stdc++.h>
using namespace std;
int value[1010], weight[1010];
int main()
{
    int n, W;
    cin >> n >> W;
    // cout << n << W << endl;
    int sum = 0;
    for(int i=0; i<n; i++)
    {
        cin >> weight[i] >> value[i];
        sum += value[i];
    }
    long long int dp[100010];
    for(int i=0; i<=sum; i++)
    {
        dp[i] = 10000000000000000;
    }
    dp[0] = 0;
    for(int i=0; i<n; i++)
    {
        for(int j=sum - value[i]; j>=0; j--)
        {
            dp[j + value[i]] = min(dp[j + value[i]], dp[j] + (long long int)weight[i]);
        }
    }

    int ans = 0;
    for(int i=1; i<=sum; i++)
    {
        if(dp[i] <= (long long int)W)
            ans = i;
    }
    cout << ans << endl;
    return 0;
}

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

vector<int> Z_Algorithm(vector<ll> s) {
    int n = s.size();
    vector<int> ret(n);
    ret[0] = n;
    int i = 1, j = 0;
    while ( i < n ) {
        while ( i+j < n && s[j] == s[i+j] ) ++j;
        ret[i] = j;
        if ( j == 0 ) {
            ++i;
            continue;
        }
        int k = 1;
        while ( i+k < n && k+ret[k] < j ) {
            ret[i+k] = ret[k];
            ++k;
        }
        i += k;
        j -= k;
    }
    return ret;
}

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    for ( int i = 0; i < N; i++ ) cin >> A[i];
    for ( int i = 0; i < N; i++ ) cin >> B[i];
    vector<ll> ab;
    for ( int i = 0; i < N; i++ ) {
        ab.push_back(B[(i+1)%N] ^ B[i%N]);
    }
    ab.push_back(-1);
    for ( int i = 0; i < 2*N-1; i++ ) {
        ab.push_back(A[(i+1)%N] ^ A[i%N]);
    }
    vector<int> match = Z_Algorithm(ab);
    for ( int k = 0; k < N; k++ ) {
        if ( match[N+1+k] == N ) {
            cout << k << " " << (A[k] ^ B[0]) << "\n";
        }
    }
    return 0;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 16872
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
#define N 500050
char w[N];
int nxt[N],n,txn[N];
bool check1(int x) {
	if(x<2) return 1;
	int t=x-nxt[x];
	return t==x||x%t>0;
}
bool check2(int x) {
	if(x>n-1) return 1;
	int t=(n-x+1)-(n-txn[x]+1);
	return t==(n-x+1)||(n-x+1)%t>0;
}
int main() {
	fread(w+1,1,500005,stdin);
	n=strlen(w+1)-1;
	if(n==1) {puts("1\n1\n"); return 0;}
	if(n==2) {
		if(w[1]==w[2]) puts("2\n1\n");
		else puts("1\n1\n");
		return 0;
	}
	int i;
	int flg=0;
	for(i=2;i<=n;i++) if(w[i]!=w[i-1]) {flg=1;break;}
	if(!flg) {printf("%d\n1\n",n); return 0;}
	nxt[1]=0;
	int j=0;
	for(i=2;i<=n;i++) {
		for(;j&&w[i]!=w[j+1];j=nxt[j]) ;
		if(w[i]==w[j+1]) j++;
		nxt[i]=j;
	}
	int t=n-nxt[n];
	if(t==n||n%t) {
		printf("1\n1\n"); return 0;
	}
	printf("%d\n",2);
	txn[n]=n+1;
	j=n+1;
	for(i=n-1;i;i--) {
		for(;j<=n&&w[i]!=w[j-1];j=txn[j]) ;
		if(w[i]==w[j-1]) j--;
		txn[i]=j;
	}
	int ans=0;
	for(i=1;i<n;i++) {
		if(check1(i)&&check2(i+1)) ans++;
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;int N,C,D[2][5001],i,j,*A,*B;
main(){A=D[0],B=D[1];cin>>N;fill_n(*D,1e4+2,1e9);A[1]=B[0]=0;for(;i++<N-1&&cin>>C;)for(j=N/2;~j;)A[j+1]=min(A[j],B[j]+C),B[j--]=min(A[j]+C,B[j]);cout<<min(A[N/2],B[N/2])<<endl;}

Measured memory_bytes: 1200
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE StrictData #-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List
import Data.Char

main :: IO ()
main = do
    [a,b,c,k] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    print $ if k <= a then k 
        else if k <= a+b then a
        else a-(k-a-b)

Measured memory_bytes: 3764
#include <cstdio>
#include <algorithm>

#pragma warning(disable: 4996)

#define MOD 100000

#define MAX_M 2000
#define MAX_S 3000

int N, M, S;

int dp[2][MAX_M + 1][MAX_S + 1];

int main()
{
	while (true)
	{
		scanf("%d", &N);
		scanf("%d", &M);
		scanf("%d", &S);

		if (N == 0 && M == 0 && S == 0) { break; }

		for (int i = 0; i < M; i++)
		{
			for (int j = 0; j < S; j++)
			{
				if (i == j && i != 0 && j != 0)
				{
					dp[1][i][j] = 1;
				}
				else
				{
					dp[1][i][j] = 0;
				}
			}
		}

		for (int n = 2; n <= N * N; n++)
		{
			for (int i = 0; i < M; i++)
			{
				dp[n % 2][i][0] = 0;
			}

			for (int j = 0; j < S; j++)
			{
				dp[n % 2][0][j] = 0;
			}

			for (int i = 1; i <= M; i++)
			{
				for (int j = 1; j <= S; j++)
				{
					if (n % 2 == 0)
					{
						dp[0][i][j] = (dp[0][i - 1][j - 1] + (j >= i ? dp[1][i - 1][j - i] : 0)) % MOD;
					}
					else
					{
						dp[1][i][j] = (dp[1][i - 1][j - 1] + (j >= i ? dp[0][i - 1][j - i] : 0)) % MOD;
					}
				}
			}
		}

		int sum = 0;

		for (int i = 1; i <= M; i++)
		{
			if (N % 2 == 0)
			{
				sum += dp[0][i][S];
			}
			else
			{
				sum += dp[1][i][S];
			}

			sum %= MOD;
		}

		printf("%d\n", sum);
	}

	return 0;
}

Measured memory_bytes: 49460
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) > (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define x first
#define y second
#define pb push_back
#define PB pop_back()
#define iOS ios_base::sync_with_stdio(false)
#define sqr(a) (((a) * (a)))
#define all(a) a.begin() , a.end()
#define error(x) cerr << #x << " = " << (x) <<endl
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define errop(a) cerr<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)
#define umap unordered_map
#define double long double
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int> vi;
typedef complex<double> point;
template <typename T> using os =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}
const int maxn = 1e5 + 100;
vector<pii> v[maxn];
vector<pii> adj[maxn];
int a[maxn];
const int inf = 1e9 + 7;
const ll INF = 1LL << 60;
bool mark[maxn];
ll d[maxn];
ll lb, mn;
inline void dfs(int v){
	mark[v] = true;
	smax(lb, d[v] - a[v]);
	smin(mn, d[v]);
	rep(p, adj[v]){
		int u = p.x, w = p.y;
		if(!mark[u]){
			d[u] = d[v] + w;
			dfs(u);
		}
		if(d[u] != d[v] + w){
			cout << "No" << endl;
			exit(0);
		}
	}
}
int main(){
	iOS;
	int r, c, n;
	cin >> r >> c >> n;
	fill(a, a + maxn, inf);
	For(i,0,n){
		int x, y, z;
		cin >> x >> y >> z;
		-- x, -- y;
		v[x].pb({y, z});
		smin(a[y], z);
	}
	For(i,0,r){
		sort(all(v[i]));
		for(int j = 0; j + 1 < (int)v[i].size(); ++ j){
			int c1 = v[i][j].x;
			int c2 = v[i][j+1].x;
			int a1 = v[i][j].y;
			int a2 = v[i][j+1].y;
			adj[c1].pb({c2, a2-a1});
			adj[c2].pb({c1, a1-a2});
		}
	}
	For(i,0,c)
		if(!mark[i]){
			lb = -INF;
			mn = INF;
			dfs(i);
			if(mn < lb){
				cout << "No" << endl;
				return 0;
			}
		}
	cout << "Yes" << endl;
	return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//end



int main(){
   string s; cin>>s;
   printf(regex_match(s,regex("(hi)+"))?"Yes":"No");
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii  = pair<int,int>;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define MOD 1000000007
#define EPS 10e-8
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数
uintmax_t combination(unsigned int n, unsigned int r){    //組み合わせ
    if ( r * 2 > n ) r = n - r;
    uintmax_t dividend = 1;
    uintmax_t divisor  = 1;
    for ( unsigned int i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return dividend / divisor;
}

int main(){
    ll S;
    cin >> S;
    if(S<1e9)
    cout <<"0 0 1 0 0 "<<S<< endl;
    else{
        ll x1 = 1e9;
        ll y2 = (S + x1 - 1) / x1;
        ll y1 = 1;
        ll x2 = x1 * y2 - S;
        cout << "0 0 "<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int,int> pa;
#define w1 first
#define w2 second
#define ls (x<<1)
#define rs (x<<1|1)
#define pb push_back
#define mp make_pair
#define mid ((l+r)>>1)
#define SZ(x) ((x).size())
#define All(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=1ll*x*x%p)if(k&1)res=1ll*res*x%p;return res;}
int getgcd(int x,int y){return !x?y:getgcd(y%x,x);}
const int maxn=5e5+5;
int n,flag,tot;
int head[maxn],des[maxn],nxt[maxn],tree[maxn],cir[maxn];
int q[maxn],d[maxn],p[maxn],v[maxn],d2[maxn],v2[maxn];
void adde(int x,int y){
	des[++tot]=y;nxt[tot]=head[x];head[x]=tot;
}
bool check(int S,int num){
	rep(i,1,n)v2[i]=v[i],d2[i]=d[i];
	v2[S]=num;
	int h=0,t=0;
	q[t++]=p[S];
	while(h!=t){
		int x=q[h++],num=0;
		vector<int>adj;
		Rep(p,x)adj.pb(v2[des[p]]);
		sort(All(adj));
		rep2(i,0,SZ(adj))if(adj[i]==num)num++;
		if(x==S)return num==v2[S];
		v2[x]=num;
		if(!--d2[p[x]])q[t++]=p[x];
	}
}
int main(){
	read(n);
	rep(i,1,n){
		read(p[i]);
		adde(p[i],i);d[p[i]]++;
	}
	int h=0,t=0;
	rep(i,1,n)if(!d[i])q[t++]=i;
	while(h!=t){
		int x=q[h++];
		vector<int>adj;
		Rep(p,x)adj.pb(v[des[p]]);
		sort(All(adj));
		rep2(i,0,SZ(adj))if(adj[i]==v[x])v[x]++;
		if(!--d[p[x]])q[t++]=p[x];
	}
	rep(x,1,n)if(d[x]){
		vector<int>adj;
		Rep(p,x)if(!d[des[p]])adj.pb(v[des[p]]);
		sort(All(adj));
		int num=0;
		rep2(i,0,SZ(adj))if(adj[i]==num)num++;
		flag|=check(x,num);
		num++;
		rep2(i,0,SZ(adj))if(adj[i]==num)num++;
		flag|=check(x,num);
		break;
	}
	if(flag)puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 17536
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;
typedef long long ll;

int main() {
    
    int X;
    cin >> X;
    int out = 0;
    for(int i=X;i<=100003;i++){
        bool isPrime = true;
        for(int j=2;j<X/2;j++){
            if(i % j == 0){
                isPrime = false;
                break;
            }
        }
        if(isPrime == true){
            out = i;
            break;
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 384
S=list(input())
N=len(S)
tsuyoikaibun=0
kaibun=0
for i in range((N-1)//2):
    if S[i]==S[(N-1)//2-i-1]and S[(N+1)//2+i]==S[N-i-1]: 
        tsuyoikaibun=tsuyoikaibun+1
    else:
        tsuyoikaibun=0
        break
for i in range (N):
    if S[i]==S[N-i-1]:
        kaibun=kaibun+1
    else:
        kaibun=0
        break
 
if kaibun==0 or tsuyoikaibun==0:
        print("No")
else:
        print("Yes")     

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

int main() {
  int H, A;
  cin >> H >> A;
  int count = 0;
  for(int i=1; true; i++){
    count = i;
    if( H <= i * A){
      break;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
using namespace std;
using ll = long long;
using ld = long double;
const ll mxn = 2e5+10;
const ll P = 200003;
ll A[mxn], cnt[P];

using cd = complex<double>;
const double PI = acos(-1);

void fft(vector<cd> & a, bool invert) {
    ll n = a.size();

    for (ll i = 1, j = 0; i < n; i++) {
        ll bit = n >> 1;
        for (; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;

        if (i < j)
            swap(a[i], a[j]);
    }

    for (ll len = 2; len <= n; len <<= 1) {
        double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (ll i = 0; i < n; i += len) {
            cd w(1);
            for (ll j = 0; j < len / 2; j++) {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }

    if (invert) {
        for (cd & x : a)
            x /= n;
    }
}

vector<ll> multiply(vector<ll> const& a, vector<ll> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    ll n = 1;
    while (n < a.size() + b.size()) 
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (ll i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<ll> result(n);
    for (ll i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}

ll Map[P];

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

	ll n; cin>>n;
	for(ll i=0; i<n; i++) {
		cin>>A[i]; cnt[A[i]]++;
	}

	vector<ll> cnt_g(P-1, 0);

	cnt_g[0] = cnt[1]; ll pr = 1;
	for(ll i=1; i<P-1; i++) {
		pr*=2; pr%=P; cnt_g[i] = cnt[pr]; Map[pr] = i;
	}

	ll sum = 0; for(ll i=1; i<P; i++) sum+=cnt[i]; for(ll i=0; i<P-1; i++) sum-=cnt_g[i]; assert(sum==0);

	vector<ll> cnt_g2 = cnt_g;
	vector<ll> res = multiply(cnt_g, cnt_g2);

	for(int i=P-1; i<res.size(); i++) {
		ll tmp = res[i]; res[i] = 0;
		res[i-P+1]+=tmp;
	}

	for(ll i=0; i<n; i++) {
		if(A[i]==0) continue;
		res[Map[A[i]*A[i]%P]]--;
	}

	ll ans = 0; ll pow = 1;
	for(ll i=0; i<P-1; i++) {
		res[i]/=2;
		ans+=pow*res[i];
		pow*=2; pow%=P;
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 31432
package main

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

func main() {
	solveC()
}

var sc = bufio.NewScanner(os.Stdin)

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

func solveC() {
	line := read_line()
	nums := make([]int, 4, 4)
	num, _ := strconv.Atoi(line)
	nums = toNums(num, nums)
	// for _, v := range nums {
	// 	fmt.Println(v)
	// }
	ops := make([]int, 0, 3)
	dfs(0, nums, ops...)
	fmt.Println("")
}

func dfs(index int, nums []int, ops ...int) bool {
	if index == 3 {
		// cal
		if isSeven(nums, ops) {
			//print
			for i := 0; i < 3; i++ {
				fmt.Printf("%d", nums[i])
				if ops[i] == 0 {
					fmt.Print("+")
				} else {
					fmt.Print("-")
				}
			}
			fmt.Printf("%d=7", nums[index])
			return true
		} else {
			return false
		}
	} else {
		ops = append(ops, 0)
		if dfs(index+1, nums, ops...) {
			return true
		}
		ops = append(ops[:index], 1)
		if dfs(index+1, nums, ops...) {
			return true
		}
	}
	return false
}

func isSeven(nums, ops []int) bool {
	sum := nums[0]
	for i, op := range ops {
		if op == 0 {
			sum += nums[i+1]
		} else {
			sum -= nums[i+1]
		}
	}
	if sum == 7 {
		return true
	} else {
		return false
	}
}

func toNums(n int, nums []int) []int {
	index := 0
	for n != 0 {
		nums[len(nums)-index-1] = n % 10
		n /= 10
		index++
	}
	return nums
}


Measured memory_bytes: 640
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long
#define ld long double
int main()
{
  ll n;
  cin >> n;
  ll mod = 1000000007;
  // ll comb = (n*(n-1))/2;
  // comb = comb % mod;
  // comb = (comb*2)%mod;
  // comb = comb % mod;
  ll v1=1;
  ll v2=1;
  ll v3=1;
  for(ll i=0;i<n;i++)
  {
    v1 = ((v1%mod)*9)%mod;
    v2 = ((v2%mod)*8)%mod;
    v3 = ((v3%mod)*10)%mod;
  }
  v1 = (v1*2)%mod;
  ll ext = (v1 - v2 + mod)%mod;
  ll ans = (v3 - ext + mod)%mod; 
  cout << ans << "\n";
}

Measured memory_bytes: 3588
#include <iostream>

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    int count = 0;
    for (int i = 1; i < a; i++){
        count++;
    }
    if(a <= b){
        count++; 
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
bool check(string s,int a,int b){
	bool jump=true;
	for (int i=a;i<=b;i++){
		if(s[i]=='#'){
			if(jump){
				jump=false;
			}else{
				return false;
			}
		}else{
			jump=true;
		}
	}
	return true;
}
bool check2(string s,int a,int b){
	int cnt=0;
	for (int i=a;i<=b;i++){
		if(s[i]=='#'){
			cnt=0;
		}else{
			cnt++;
			if(cnt>=3)return true;
		}
	}
	return false;
}


int main(){
	int n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	a--;
	b--;
	c--;
	d--;
	string s;
	cin>>s;
	if(c<d){
		if(check(s,a,c)&&check(s,b,d)){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}else{
		if(check(s,a,c)&&check(s,b,d)&&check2(s,b-1,d+1)){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1156
import collections
N = int(input())

t = collections.defaultdict(int)
ans = 0

for _ in range(N):
    s = list(input())
    s.sort()
    t[''.join(s)] += 1


for x in t:
    ans += (t[x] * (t[x] - 1)) // 2

print(ans)


Measured memory_bytes: 18192
from collections import deque
N = int(input())
lis = []

A = []
B = []
for i in range(N):
    Ain,Bin = map(int,input().split())
    A.append(Ain)
    B.append(Bin)
    lis.append((Ain+Bin,i))
lis.sort()
lis.reverse()
lis = deque(lis)

takacnt = 0
aocnt = 0

# print(taka)
# print(ao)

for i in range(N):
    if i % 2 == 0:
        val = lis.popleft()
        takacnt += A[val[1]]
    else:
        val = lis.popleft()
        aocnt += B[val[1]]
print(takacnt-aocnt)


Measured memory_bytes: 93400
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n,d[305];
int dp[305][305][2],ans;
int fac[305],ifac[305];

int ksm(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=1ll*res*x%mod;
		x=1ll*x*x%mod,y/=2;
	}
	return res;
}

int main(){
	scanf("%d",&n);
	int flag=1;
	for(int i=1;i<=n;i++) scanf("%d",&d[i]),flag&=(d[i]==2);
	dp[0][0][0]=1;
	fac[0]=1;for(int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=ksm(fac[n],mod-2);
	for(int i=n-1;i>=0;i--) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
	if(flag){
		if(n>=3) printf("%d\n",1ll*fac[n-1]*ifac[2]%mod);
		else puts("0");return 0;
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<i;j++){
			if(d[i]>=3) (dp[i][j+1][1]+=1ll*ifac[d[i]-3]*dp[i-1][j][0]%mod)%=mod;
			if(d[i]>=2){
				(dp[i][j+1][0]+=1ll*ifac[d[i]-2]*dp[i-1][j][0]%mod)%=mod;
				(dp[i][j+1][1]+=1ll*ifac[d[i]-2]*dp[i-1][j][1]%mod)%=mod;
			}
			(dp[i][j][0]+=1ll*ifac[d[i]-1]*dp[i-1][j][0]%mod)%=mod;
			(dp[i][j][1]+=1ll*ifac[d[i]-1]*dp[i-1][j][1]%mod)%=mod;
		}
	}
	for(int i=3;i<n;i++) (ans+=1ll*dp[n][i][1]*fac[i-1]%mod*ifac[2]%mod*fac[n-i-1]%mod)%=mod;
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 1024
MOD = 10 ** 9 + 7
fact_len = 10 ** 5
fact = [-1] * (fact_len + 2)
for i in range(fact_len + 1):
    fact[i + 1] = fact[i] * (i + 1)
    fact[i + 1] %= MOD

N, M = map(int, input().split())
if abs(N - M) > 1:
    print(0)
elif N == M:
    print(fact[N] * fact[M] * 2 % MOD)
else:
    print(fact[N] * fact[M] % MOD)


Measured memory_bytes: 6900