akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
using ll = long long;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
using namespace std;
#define mp make_pair
signed main(){
    int n; cin>>n;
    vector<int>ans;
    map<int,vector<int>>Mp;
    vector<int>v(n);
    rep(i,n)cin>>v[i];
    rep(i,n){
        Mp[v[i]].push_back(i+1);
    }
    rep(i,Mp[2].size())ans.push_back(Mp[2][i]);
    
    if(Mp[-2].size()%2&&Mp[-1].size()>0){
        
        rep(i,Mp[-2].size())ans.push_back(Mp[-2][i]);
        ans.push_back(Mp[-1].front());
        
    }else if(Mp[-2].size()%2&&Mp[-1].size()==0)
        
        rep(i,Mp[-2].size()-1)ans.push_back(Mp[-2][i]);
    
    else if(Mp[-2].size()%2==0LL)
        rep(i,Mp[-2].size())ans.push_back(Mp[-2][i]);
    
    sort(all(ans));
    if(ans.size()==0)cout<<0<<endl;
    else{
        cout<<ans.size()<<endl;
        rep(i,ans.size())cout<<ans[i]<<endl;
    }
}



Measured memory_bytes: 3152
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int N, H, W;
    int ans = 0;
    int A, B;

    cin >> N >> H >> W;
    for (int i = 0; i < N; i++)
    {
        cin >> A >> B;
        if (A >= H && B >= W)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int N; cin >> N;
    int res = N % 10;

    if (res == 2 || res == 4 || res == 5 || res == 7 || res == 9) cout << "hon" << endl;
    else if (res == 0 || res == 1 || res == 6 || res == 8) cout << "pon" << endl;
    else cout << "bon" << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
using namespace std;

int value(int wei, int fin);

int memo[10001][101];//重さ[10001]まで&個数[101]個まで入れたときの価値のmax
int n, w, v[100], we[100];

int main() {

	for (int i = 0; i < 10001; i++) {	//メモ初期化
		for (int j = 0; j < 101; j++) {
			memo[i][j] = i * j == 0 ? 0 : INT32_MAX;	//"重さNまで"制限or"N個目まで"制限が0なら価値は0,その他はMAXに初期化
		}
	}

	cin >> n >> w;	//入力
	for (int i = 0; i < n; i++) {
		cin >> v[i] >> we[i];
	}

	cout << value(w, n) << endl;	//出力
	return 0;
}

int value(int wei, int fin) {
	if (memo[wei][fin] == INT32_MAX) {	//メモしてないなら計算
		memo[wei][fin] = wei - we[fin - 1] >= 0 ? max(value(wei, fin - 1), value(wei - we[fin - 1], fin - 1) + v[fin - 1]) : value(wei, fin - 1);	//fin個目([fin-1])を加えたほうがいいか
	}
	return memo[wei][fin];
}



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

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

  string s;
  cin >> s;

  if (s.back() == 's') s += 'e';
  s += 's';

  cout << s << '\n';
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
const int MOD = 1e9 + 7;

int main(){
		
		string s;
		cin>>s;
		
		if(s[1] == 'R')
			cout<<"ABC";
		else
			cout<<"ARC";
		return 0;
}




Measured memory_bytes: 3552
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
#define LL long long

int n, m, k;

int main()
{
    while(cin >> n >> m >> k)
    {
        int flag = 0;
        for(int i = 0; i <= n; ++i)
        {
            for(int j = 0; j <= m; ++j)
            {
                int temp = n * j + m * i - 2 * i * j; //cout << i << ".." << j << ".." << temp << endl;
                if(temp == k) flag = 1;
            }
        }
        if(flag) printf("Yes\n");
        else printf("No\n");
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
  ll N,K,Q;
  cin >> N >> K >> Q;
  vector<ll> A(Q);
  for(int i = 0; i < Q; i++){
    cin >> A[i];
  }
  vector<ll> point(N,K-Q);
  
  for(int i = 0; i < Q; i++){
    point[A[i]-1]++;
  }

  for(int i = 0; i < N; i++){
    if(point[i] > 0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }


}

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

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


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;
static const long long INF = 1<<31;

int n, m;
vector<pair<int, ll> > g[100005];
ll d[100005];

bool bfs(int s) {
  queue<int> q;
  if (d[s] == INF) d[s] = 0;
  q.push(s);
  while (!q.empty()) {
    int u = q.front(); q.pop();
    for (auto v : g[u]) {
      if (d[v.first] != INF) {
        if (d[u] + v.second != d[v.first]) return false;
      } else {
        d[v.first] = d[u] + v.second;
        q.push(v.first);
      }
    }
  }
  return true;
}

int main(void) {
  cin >> n >> m;
  rep(i, 0, m) {
    int l, r;
    ll d;
    scanf("%d %d %lld", &l, &r, &d);
    g[l].pb(mp(r, d));
    g[r].pb(mp(l, d*-1));
  }
  
  rep(i, 1, n+1) d[i] = INF;
  
  rep(i, 1, n+1) {
    if (d[i] == INF && !bfs(i)) {
      puts("No");
      return 0;
    }
  }
  
  puts("Yes");
    
    //cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 13824
from operator import itemgetter

class UnionFindTree():
    def __init__(self, N):
        self.__parent_of = [None] * N
        self.__rank_of = [0] * N
        self.__size = [1] * N

    def root(self, value):
        if self.__parent_of[value] is None:
            return value
        else:
            self.__parent_of[value] = self.root(self.__parent_of[value])
            return self.__parent_of[value]

    def unite(self, a, b):
        r1 = self.root(a)
        r2 = self.root(b)
        if r1 != r2:
            if self.__rank_of[r1] < self.__rank_of[r2]:
                self.__parent_of[r1] = r2
                self.__size[r2] += self.__size[r1]
            else:
                self.__parent_of[r2] = r1
                self.__size[r1] += self.__size[r2]
                if self.__rank_of[r1] == self.__rank_of[r2]:
                    self.__rank_of[r1] += 1

    def is_same(self, a, b):
        return self.root(a) == self.root(b)

    def size(self, a):
        return self.__size[self.root(a)]

    def groups(self):
        groups = {}
        for k in range(len(self.__parent_of)):
            r = self.root(k)
            if r not in groups:
                groups[r] = []
            groups[r].append(k)
        return [groups[x] for x in groups]


def main():
    N = int(input())
    uft = UnionFindTree(N)
    P = [None] * N
    for i in range(N):
        x, y = map(int, input().split())
        P[i] = (i, x, y)
    Q = sorted(P, key=itemgetter(1))
    for i in range(1, N):
        if Q[i-1][1] == Q[i][1]:
            uft.unite(Q[i-1][0], Q[i][0])
    R = sorted(P, key=itemgetter(2))
    for i in range(1, N):
        if R[i-1][2] == R[i][2]:
            uft.unite(R[i-1][0], R[i][0])
    groups = uft.groups()
    ans = 0
    for g in groups:
        if len(g) < 3:
            continue
        xs = set()
        ys = set()
        for i in g:
            _, x, y = P[i]
            xs.add(x)
            ys.add(y)
        ans += len(xs) * len(ys) - len(g)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 100696
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}

int main(int argc, char *argv[]){
    int h, w; cin >> h >> w;
    vector<string> A(h);
    rep(i, h) cin >> A[i];
    // rep(i, h) A[i][0] = A[i][w - 1] = '#';
    // rep(i, w) A[0][i] = A[h - 1][i] = '#';
    rep(i, w + 2) cout << "#";
    cout << endl;
    rep(i, h){
        cout << "#";
        cout << A[i];
        cout << "#" << endl;
    }
    rep(i, w + 2) cout << "#";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    ll n, m;
    cin >> n >> m;

    ll start = m/n;
    while(start > 1){
        int mod = m%start;
        if(mod%start==0){
            break;
        }
        --start;
    }

    cout << start << endl;

    return 0;
}

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

using namespace std;


int main(){
    
    
    vector<vector<int> > c(3, vector<int>(3));
    
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }
    
    
    vector<int> a(3);
    vector<int> b(3);
    
    a[0] = 0;
    for (int i = 0; i < 3; i++) {
        b[i] = c[0][i];
    }
    
    
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];
    
    
    bool aaa = true;
    for (int i = 1; i <= 2; i++) {
        for (int j = 1; j <= 2; j++) {
            if (c[i][j] != a[i]+b[j]) {
                aaa = false;
            }
        }
    }
    if (aaa) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    
}


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

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

int main() {
    int n, X;
    int x[100000];
    cin >> n >> X;
    for (int i = 0; i < n; i++) cin >> x[i];

    int ans = abs(X - x[0]);
    for (int i = 1; i < n; i++) {
        ans = gcd(ans, abs(X - x[i]));
    }

    cout << ans << endl;
}

Measured memory_bytes: 3912
# 入力値を文字の配列で返す
def gets_s_list()
  gets.chomp.split("")
end

s_list = gets_s_list

count = 0
w_count = 0
s_list.each_with_index do |s, i|
  if s == "W"
    count += i - w_count
    w_count += 1
  end
end
puts count


Measured memory_bytes: 16764
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long,long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N;
    cin >> N;
    veci L(N);
    REP(i,N) cin >> L[i];
    sort(L.begin(),L.end());
    int ans = 0;
    for(int i = 0; i < N-2; i++) {
        int k = i;
        for(int j = i+1; j < N-1; j++) {
            while(k < N && L[k] < L[i] + L[j]) k++;
            ans += k-(j+1);
            if(j == k) k++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3600
use std::collections::{BTreeMap, BTreeSet, VecDeque};
const INF: u64 = 1 << 50;
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut graph = vec![BTreeMap::new(); n];
    for _ in 0..m {
        let p = sc.read::<usize>() - 1;
        let q = sc.read::<usize>() - 1;
        let c: usize = sc.read();
        graph[p].entry(c).or_insert_with(Vec::new).push(q);
        graph[q].entry(c).or_insert_with(Vec::new).push(p);
    }

    let mut dist = BTreeMap::new();
    dist.insert((0, 0), 0);
    let mut q = VecDeque::new();
    q.push_back((0, 0));
    while let Some((v, c)) = q.pop_front() {
        let d = dist[&(v, c)];
        if v == n - 1 {
            println!("{}", d);
            return;
        }

        if c == 0 {
            for (&next_c, next) in graph[v].iter() {
                for &next in next.iter() {
                    let cost = 1;
                    let cur = dist.entry((next, next_c)).or_insert(INF);
                    if *cur > d + cost {
                        *cur = d + cost;
                        q.push_back((next, next_c));
                    }
                }
            }
        } else {
            if let Some(next) = graph[v].get(&c) {
                for &next in next.iter() {
                    let cost = 0;
                    let cur = dist.entry((next, c)).or_insert(INF);
                    if *cur > d + cost {
                        *cur = d + cost;
                        q.push_front((next, c));
                    }
                }
            }
        }

        if c != 0 {
            let cur = dist.entry((v, 0)).or_insert(INF);
            if *cur > d {
                *cur = d;
                q.push_front((v, 0));
            }
        }
    }

    println!("-1");
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 76028
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,m,l;
    cin>>n>>m>>l;
    int a[n][m];
    int b[m][l];
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>a[i][j];
    for(int i=0;i<m;i++)
        for(int j=0;j<l;j++)
            cin>>b[i][j];
    
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            long long sum = 0;
            for(int k=0;k<m;k++){
                sum+=a[i][k]*b[k][j];
            }
            cout << sum;
            if(j!=l-1)
                cout << " ";
        }
        cout << endl;
    }
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	rep(i, m) {
		int k;
		cin >> k;
		rep(j, k) {
			int s;
			cin >> s;
			s--;
			a[s] |= 1<<i; 
		}
	}

	int p = 0;
 	rep(i, m) {
 		int x;
 		cin >> x;
 		p |= x<<i;
 	}

	int ans = 0;
	for (int s = 0; s<(1<<n); s++) {
		int t = 0;
		for (int i = 0; i < n; i++) {
			if (s>>i&1) {
				t ^= a[i];
			}
		}
		if (t == p) ans++;
	}

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


Measured memory_bytes: 256
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)


def main():
    N, Q = MAP()
    S = INPUT()
    
    L = [0]
    for i in range(N-1):
        L.append(L[-1] + (1 if S[i:i+2] == "AC" else 0))

    ans = []
    for i in range(Q):
        l, r = MAP()
        ans.append(L[r-1] - L[l-1])

    print(*ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 13448
/*input
8 6
50000000 30000000
*/
fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        return a;
    }
    return gcd(b, a % b);
}

fn lcm(a: u64, b: u64) -> u64 {
    return a * b / gcd(a, b);
}

fn main() {
    let mut input;
    let mut v: Vec<u64>;
    loop {
        input = format!("");
        match std::io::stdin().read_line(&mut input) {
            Ok(0) => {
                break;
            }
            _ => {}
        }
        v = input
            .trim()
            .split_whitespace()
            .map(|x| x.parse().expect(""))
            .collect();
        println!("{} {}", gcd(v[0], v[1]), lcm(v[0], v[1]));
    }
}



Measured memory_bytes: 5024
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

void trace(int A[], int N)
{
	int i;
	for (i = 0; i < N; i++) {
		if (i > 0)
			cout << " ";
		cout << A[i];
	}
	cout << endl;
}

void insertionSort(int A[], int N) {
	int i,v,j;
	for (i = 1; i < N; i++) {
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v)
		{
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		trace(A, N);
	}
}


int main(){
	int N, i;
	int A[100];

	cin >> N;
	for (i = 0; i < N; i++) cin >> A[i];

	trace(A, N);
	insertionSort(A, N);

	return 0;
}


Measured memory_bytes: 3088
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int N;
int cnt[200000];
int main(){
  int Lj4PdHRW;
  rd(N);
  for(Lj4PdHRW=(0);Lj4PdHRW<(N-1);Lj4PdHRW++){
    cnt[rd_int()-1]++;
  }
  {
    int e98WHCEY;
    for(e98WHCEY=(0);e98WHCEY<(N);e98WHCEY++){
      wt_L(cnt[e98WHCEY]);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20200419-1

// --- original code ---
// int N, cnt[2d5];
// {
//   rd(N);
//   rep(N-1) cnt[rd_int()-1]++;
//   wtLn(cnt(N));
// }


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

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  rep(i, N) cin >> S[i];
  map<string,int> mp;
  rep(i, N){
      mp[S[i]] = 1;
  }
  int ans = mp.size();
  cout << ans << endl;
}

Measured memory_bytes: 25096
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {
	
	
	int n;
	cin >> n;
	map<string, int>f;
	set<string>s;
	long long int t[8] = {};
	for (int i = 0; i < n; i++) {
		string a;
		cin >> a;
		if (f[a])continue;
		if (a[0] != 'M'&&a[0] != 'A'&&a[0] != 'R'&&a[0] != 'C'&&a[0] != 'H')continue;
		f[a]++;
		s.insert(a);
		if (a[0] == 'M')t[0]++;
		if (a[0] == 'A')t[1]++;
		if (a[0] == 'R')t[2]++;
		if (a[0] == 'C')t[3]++;
		if (a[0] == 'H')t[4]++;

	}
	long long int ans = 0;
	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += t[i] * t[j] * t[k];
			}
		}
	}
	cout << ans << endl;

	

	return 0;

}

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

using namespace std;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b==c+d)cout<<"Balanced"<<endl;
  else if(a+b>c+d)cout<<"Left"<<endl;
  else cout << "Right"<<endl;
}


Measured memory_bytes: 256
from collections import deque
X = input()
que = deque()
for x in X:
    if x=='S':
        que.append('S')
    elif x=='T' and (not que or que[-1]=='T'):
        que.append('T')
    elif x=='T' and que[-1]=='S':
        _ = que.pop()
print(len(que))

Measured memory_bytes: 10776
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <climits>
#include <utility>
#define N 100020
#define M 10000020
using namespace std;

int h[N << 2], v[M], w[M], x[M];
int k[N];
long long d[N << 2];
pair<long long, int> f[N << 4];

void AddEdge(int u, int v, int w)
{
    static int c;

    x[++ c] = h[u];
    h[u] = c;
    ::v[c] = v;
    ::w[c] = w;

    return;
}

void InitSegment(int x, int l, int r)
{
    int m;

    if(l == r)
    {
        k[l] = x;

        return;
    }

    m = (l + r) >> 1;
    InitSegment(x << 1    , l    , m);
    InitSegment(x << 1 | 1, m + 1, r);
    AddEdge(x << 1    , x, 0);
    AddEdge(x << 1 | 1, x, 0);

    return;
}

void AddSegment(int x, int l, int r, int s, int t, int k, int w)
{
    int m;

    if(l > t || r < s)
        return;
    if(l >= s && r <= t)
    {
        AddEdge(x, k, w);

        return;
    }

    m = (l + r) >> 1;
    AddSegment(x << 1    , l    , m, s, t, k, w);
    AddSegment(x << 1 | 1, m + 1, r, s, t, k, w);

    return;
}

void InitSegwin(int n)
{
    int i;

    for(i = 0; i < n; i ++)
        f[i + n] = make_pair(LLONG_MAX >> 2, i);
    for(i = n - 1; i > 0; i --)
    {
        f[i].first = min(f[i << 1].first, f[i << 1 | 1].first);
        f[i].second = f[i << 1].first < f[i << 1 | 1].first ? f[i << 1].second : f[i << 1 | 1].second;
    }

    return;
}

void SetSegwin(int p, long long v, int n)
{
    for(f[p += n].first = v; p >>= 1; )
    {
        f[p].first = min(f[p << 1].first, f[p << 1 | 1].first);
        f[p].second = f[p << 1].first < f[p << 1 | 1].first ? f[p << 1].second : f[p << 1 | 1].second;
    }

    return;
}

int main(void)
{
    int n, m, l, r, w;
    int i, t;

    scanf("%d %d", &n, &m);
    InitSegment(1, 1, n);
    while(m --)
    {
        scanf("%d %d %d", &l, &r, &w);
        AddSegment(1, 1, n, l, r - 1, k[r], w);
    }

    for(i = 0; i < (n << 2); i ++)
        d[i] = LLONG_MAX >> 2;
    InitSegwin(n << 2);
    d[k[1]] = 0;
    SetSegwin(k[1], 0, n << 2);

    while(f[1].first != LLONG_MAX >> 2)
    {
        t = f[1].second;
        // printf("%d %lld %lld\n", t, d[t], f[1].first);
        SetSegwin(t, LLONG_MAX >> 2, n << 2);
        for(i = h[t]; i; i = x[i])
            if(d[v[i]] > d[t] + ::w[i])
            {
                d[v[i]] = d[t] + ::w[i];
                SetSegwin(v[i], d[v[i]], n << 2);
            }
    }
    printf("%lld\n", d[k[n]] == LLONG_MAX >> 2 ? -1 : d[k[n]]);

    return 0;
}


Measured memory_bytes: 40192
#include<stdio.h>
int d[90][90],n,m;
const int X[]={0,1,0,-1};
const int Y[]={1,0,-1,0};
int f(int y,int x,int t){
  int i,max=t,ny,nx,r;
  for(i=0;i<4;i++){
    nx=x+X[i];
    ny=y+Y[i];
    if(nx<0||ny<0||n<=nx||m<=ny)continue;
    if(d[ny][nx]==0)continue;
    d[ny][nx]=0;
    r=f(ny,nx,t+1);
    if(max<r)max=r;
    d[ny][nx]=1;
  }
  return max;
}
int main(){
  int i,max,r,j;
  while(scanf("%d %d",&n,&m),n||m){
    for(i=0;i<m;i++){
      for(j=0;j<n;j++)scanf("%d",&d[i][j]);
    }
    for(i=max=0;i<m;i++){
      for(j=0;j<n;j++){
	if(d[i][j]==0)continue;
	d[i][j]=0;
	r=f(i,j,1);
	if(max<r)max=r;
	d[i][j]=1;
      }
    }
    printf("%d\n",max);
  }
  return 0;
}

Measured memory_bytes: 632
#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 mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


const int N=1e6+6;
ll fac[N];
void compute()
{ 
    fac[0]=1;
    ll i;
    for(i=1;i<N;i++)
    {
        fac[i]=fac[i-1]*i%mod;
        fac[i]%=mod;
    }
}

long long power(long long x, long long y, long long p)
{
long long res = 1;


x = x % p;


while (y > 0)
{
if (y & 1)
res = (res*x) % p;


y = y>>1;
x = (x*x) % p;
}
return res;
}

long long modInverse(long long n, long long p)
{
return power(n, p-2, p);
}


long long ncrp(long long n, long long r, long long p)
{


if (r==0)
return 1;




 return (fac[n]* modInverse(fac[r], p) % p *modInverse(fac[n-r], p) % p) % p;
}


void solve()
{
    ll n;
    cin>>n;
    ll res=0;
    res+=power(10,n,mod);
    res%=mod;
    res-=2*power(9,n,mod);
    res%=mod;
    res+=mod;
    res%=mod;
    res+=power(8,n,mod);
    res%=mod;
    cout<<res<<"\n";
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

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

int c[6], cost[110][1 << 6], m, n, k, d;
struct st {
	int a, b, c;
}v[600];
int num(string s) {
	if (s == "H")return m + n;
	if (s == "D")return m + n + 1;
	if (s[0] == 'C')return s[1] - '1';
	return stoi(s.substr(1)) - 1 + m;
}
int main() {
	while (scanf("%d%d%d%d", &m, &n, &k, &d), m) {
		rep(i, m)scanf("%d", &c[i]);
		rep(i, d) {
			string s, t; int e; cin >> s >> t >> e; e *= k;
			int a = num(s), b = num(t);
			v[i * 2] = { a,b,e };
			v[i * 2 + 1] = { b,a,e };
		}
		memset(cost, 0x3f, sizeof(cost));
		cost[m + n][0] = 0;
		bool update = true;
		while (update) {
			update = false;
			rep(j, 2 * d) {
				st&e = v[j];
				rep(i, 1 << m) {
					if (cost[e.a][i] == INF)continue;
					if (e.b < m) {
						if (!(i >> e.b & 1) && cost[e.b][i | 1 << e.b] > cost[e.a][i] + e.c - c[e.b])
							cost[e.b][i | 1 << e.b] = cost[e.a][i] + e.c - c[e.b], update = true;
					}
					else if (cost[e.b][i] > cost[e.a][i] + e.c)
						cost[e.b][i] = cost[e.a][i] + e.c, update = true;
				}
			}
		}
		int Min = INF;
		rep(i, 1 << m)Min = min(Min, cost[m + n + 1][i]);
		printf("%d\n", Min);
	}
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define endl "\n"     
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=1e5+5;

int vis[N],ans[N];
vector <int> g[N];

int dfs(int k)
{
     if(vis[k])
          return ans[k];
     vis[k]=1;
     for(auto &itr:g[k])
          ans[k]=max(ans[k],1+dfs(itr));
     return ans[k];     
}

int32_t main()
{
     int n,m;
     cin>>n>>m;
     for(int i=1;i<=m;i++)
     {
          int x,y;
          cin>>x>>y;
          g[x].pb(y);
     }
     int ans1=0;
     for(int i=1;i<=n;i++)
          ans1=max(ans1,dfs(i));
     cout<<ans1;     
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int h, w; cin >> h >> w;
    FOR(i, 0, h) {
        string s; cin >> s;
        cout << s << "\n" << s << "\n";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define eps 1e-8

using namespace std;

int main()
{
	cin.tie(0),ios::sync_with_stdio(0);
	ll n,m;
	cin>>n>>m;
	vector<pair<ll,ll>> arr(n);
	for(int i=0;i<n;i++)
		cin>>arr[i].first>>arr[i].second;
	sort(arr.begin(),arr.end());
	ll ans=0;
	for(int i=0;i<n&&m;i++)
	{
		int tmp=min(arr[i].second,m);
		m-=tmp;
		ans+=arr[i].first*tmp;
	}
	cout<<ans<<'\n';
	return 0;
} 

Measured memory_bytes: 1792
N=int(input())
P=list(map(int, input().split()))
A,B=[0]*N,[0]*N

for i in range(N):
  A[i]=20001*(i+2)
  B[i]=20001*(N-i)
for i in range(N):
  a=P[i]-1
  A[a]+=i
print(*A)
print(*B)

Measured memory_bytes: 11512
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//関係性は隣接行列で記録
//過半数：N/2.0で判定
//ある量からある量を引く系の問題：端から定義してやる
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll N, M; cin >> N >> M;
	vector<ll> A(N); rep(i, N)cin >> A[i];

	ll sum = 0;
	rep(i, N)sum += A[i];

	ll ans = 0;
	rep(i, N) {
		if (4 * M * A[i] >= sum) ans++;
	}

	if (ans >= M)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

const int N = 500010;

int n, d;
int A[N], pos[N];
bool ok[N];

int main(){
	scanf("%d%d", &n, &d);
	pos[0] = d;
	For(i, 1, n){
		scanf("%d", &A[i]);
		int x = abs(A[i] - pos[i - 1]);
		pos[i] = min(x, pos[i - 1]);
	}
	int Mind = 1;
	Forr(i, n, 1){
		ok[i] = pos[i - 1] >= Mind;
		if(A[i] < Mind * 2LL) Mind += A[i];
	}
	int q;
	scanf("%d", &q);
	while(q--){
		int x;
		scanf("%d", &x);
		puts(ok[x] ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 6272
#include<iostream>
#include<cstdio>
using namespace std;
long long a[100],n,p,b,c1[50],c2[50],i,j,m1,m2,maxx=0;
long long ans1,ans2;
int main(){
	
	
	cin>>n>>p;
	p%=2;
	
	for(i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]%2){
			m1++;
		}else{
			m2++;
		}
	}
	
	c1[0]=1;
	c2[0]=1;
	for(i=1;i<=m1;i++){
	    c1[i]=c1[i-1]*(m1-i+1)/i;
	   // cout<<c1[i]<<endl;
	     maxx=max(maxx,c1[i]);
	  
	}
	for(i=1;i<=m2;i++){
		c2[i]=c2[i-1]*(m2-i+1)/i;
	}
//	ans=0;
	if(p){//1
	    
	    for(i=0;i<=m2;i++){
	    	for(j=1;j<=m1;j+=2){
	    		ans1+=(c2[i]%10000)*(c1[j]/10000)%10000*10000+(c2[i]/10000)*(c1[j]%10000)%10000*10000+(c2[i]%10000)*(c1[j]%10000);
				ans2+=(c2[i]/10000)*(c1[j]/10000)+(c2[i]%10000)*(c1[j]/10000)/10000+(c2[i]/10000)*(c1[j]%10000)/10000;
	    		if(ans1>100000000){
	    			ans2+=ans1/100000000;
	    			ans1%=100000000;
	    		}
	    	}
	    }
	
	}else{
		for(i=0;i<=m2;i++){
			for(j=0;j<=m1;j+=2){
				ans1+=(c2[i]%10000)*(c1[j]/10000)%10000*10000+(c2[i]/10000)*(c1[j]%10000)%10000*10000+(c2[i]%10000)*(c1[j]%10000);
				ans2+=(c2[i]/10000)*(c1[j]/10000)+(c2[i]%10000)*(c1[j]/10000)/10000+(c2[i]/10000)*(c1[j]%10000)/10000;
	    		if(ans1>100000000){
	    			ans2+=ans1/100000000;
	    			ans1%=100000000;
	    		}
			}
		}
	}
	if(ans2>0){
		cout<<ans2<<ans1<<endl;
	}else{
		cout<<ans1;
	}
	
}





Measured memory_bytes: 256
import sys
def main():
    INF=sys.maxsize
    N,K=tuple(map(int,sys.stdin.readline().split()))
    h=tuple(map(int,sys.stdin.readline().split()))
    dp=[INF for _ in range(N)]
    dp[0]=0
    for i in range(N-1):
        for j in range(1,K+1):
            if i+j<N:dp[i+j]=min([dp[i+j],dp[i]+abs(h[i+j]-h[i])])
    print(dp[N-1])
if __name__=='__main__':main()

Measured memory_bytes: 92684
#include<bits/stdc++.h>
#define inf INT_MAX
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("%d %d",&a,&b)
#define sccc(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pff(a,b) printf("%d %d",a,b)
#define pfff(a,b,c) printf("%d %d %d",a,b,c)
#define pb(a) push_back(a)
#define em empty()
#define fr front()
#define cl clear()
#define sz size()
#define mp(a,b) make_pair(a,b)
#define fri(b) freopen(b,"r",stdin)
#define fro(b) freopen(b,"w",stdout)
/*
ID: uslusam1
TASK: test
LANG: C++
*/
using namespace std;


int main(){
	//	fri(".in");
	//	fro(".out");
	string st;
	cin>>st;
	int a=0;
	int b=st.size()-1;
	int cnt=0;
	while(a<b){
		if(st[a]!=st[b]){
			cnt++;
		}
		a++;
		b--;
	}
	cout<<cnt<<endl;
	
	return 0;
}








Measured memory_bytes: 256
s = input()

for i in range(2**3):
    ss = ''
    for j in range(4):
        ss += s[j]
        if j < 3:
            if (i >> j) & 1 == 1:
                ss += '+'
            else:
                ss += '-'
    if eval(ss) == 7:
        break
print(ss+'=7')

Measured memory_bytes: 8992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using WeightedGraph = vector<vector<pair<int, int>>>;
const int INF = 1 << 29;

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

int h, w;
int gx, gy;
vector<string> s;
vector<char> s_;
vector< vector<int> > steps;

vector<int> dijkstra(int s, WeightedGraph & G){
  using P = pair<ll, int>;
  int n=G.size();
  vector<int> ds(n,INF);
  vector<int> bs(n,-1);
  priority_queue<P, vector<P>, greater<P> > pq;
  ds[s]=0;
  pq.emplace(ds[s],s);
  while(!pq.empty()){
    P p=pq.top();pq.pop();
    int v=p.second;
    if(ds[v]<p.first) continue;
    for(auto& e:G[v]){
      int u=e.first;
      ll c=e.second;
      if(s_[v] != '#' && s_[u] == '#'){
          ++c;
      }
      if(ds[u]>ds[v]+c){
        ds[u]=ds[v]+c;
        bs[u]=v;
        pq.emplace(ds[u],u);
      }
    }
  }
  // return bs; // 経路
  return ds;
}


int main() {

    cin >> h >> w;
    gx = w-1; gy = h-1;

    s.resize(h);
    for(int i = 0;i < h; i++){
        cin>>s[i];
    }
    WeightedGraph G(w*h);
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if(i<h-1)G[i*w+j].push_back({(i+1)*w+j,0});
            if(j<w-1)G[i*w+j].push_back({i*w+j+1,0});
            s_.push_back(s[i][j]);
        }
    }
    auto ds = dijkstra(0, G);
    int cur = 0;
    if(s[0][0]=='#') ++cur;
    cout << ds[h*w-1] +cur << endl;
    return 0;
}


Measured memory_bytes: 896
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int s = sc.nextInt();
    int count = 0;
    int stack;
    
    int start = 0;
    if(s - 2*k > 0) start = s - 2*k;
    
    int end = k;
    if(s < k) end = s;
        
    for(int x = 0; x <= k; x++){
    	stack = s - x;
      	if(stack <= 2*k && stack >= 0){
      		if(stack <= k) count += stack + 1;
      		else count += k - (stack - k) + 1;
        }
    } 
   	
  	System.out.println(count);

  }
}


Measured memory_bytes: 35628
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define sigma_size 30
#define max_size (int)(1e5+10)
#define MAX (int)(1e5+7)

int N;
int a[max_size];
const int INF = 1e9+7;
int main ()
{
	ios::sync_with_stdio(0);
	cin >> N ;
	vector <int> v;
	v.push_back(0);
	for ( int i = 1 ; i <= N ; i++ )
		cin >> a[i];
	for ( int i = 1 ; i <= N ; i++ )
	{
		if ( v.size() == 1 )
		{
			v.push_back(a[i]);
			continue;
		}
		int left = 1 , right = (int)v.size();
		while ( left < right )
		{
			int mid = left + right >> 1;
			if ( v[mid] < a[i] )
				right = mid;
			else left = mid+1;
		}
		if ( left == (int)v.size() )
			v.push_back(a[i]);
		else v[left] = a[i];
	}
	cout << v.size()-1 << endl;
}

Measured memory_bytes: 4312
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> A(N), B(N);
  vector<vector<pair<ll, ll>>> cnt(3);
  rep(i, N) {
    cin >> A[i] >> B[i];
    if(A[i] < B[i]) cnt[0].push_back({A[i], B[i]});
    else if(A[i] == B[i]) cnt[1].push_back({A[i], B[i]});
    else cnt[2].push_back({A[i], B[i]});
  }
  ll ans = 0;
  if(cnt[0].size() == 0) { // all equal
    ans = 0;
  } else {
    for(auto ele: cnt[0]) ans += ele.first;
    for(auto ele: cnt[1]) ans += ele.first;
    sort(all(cnt[2]), [&](pair<ll, ll>& p1, pair<ll, ll>& p2) {
        return p1.second < p2.second;
      });
    rep(i, cnt[2].size()) {
      if(i) ans += cnt[2][i].first;
      else  ans += cnt[2][i].first - cnt[2][i].second;
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4192
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	int N,X;
	vector<int> m;
	cin >> N >> X;
	m.resize(N);
	for(int i=0;i<N;i++) cin >> m[i];
	
	int mi = (int) 1e9;
	for(auto n : m){
		X -= n;
		mi = min(mi, n);
	}
	
	int ans = N;
	ans += X / mi;
	cout << ans << endl;
	
	
    return 0;
}

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

#define NUM 100000

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

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;
#define START 0
#define FORWARD 1
#define BACK 2
using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;
bool comp(const pll &a, const pll &b) {
	return a.first < b.first;
}
//*********************************************************
// 最大公約数（Greatest Common Divisor）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
ll gcd(ll a, ll b)
{
	ll tmp, r;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
	//// 引数に０がある場合は０を返す
	//if ((0 == m) || (0 == n))
	//	return 0;

	//// ユークリッドの方法
	//while (m != n)
	//{
	//	if (m > n) m = m - n;
	//	else         n = n - m;
	//}
	//return m;
}//gcd

int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll x[100004] = {};
	ll y[100004] = {};
	ll z[2003][2003] = { {} };
	vector<tuple<ll, ll>> vec;
	string s;
	string t;
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);
	//cout << LLONG_MAX<< endl;

	cin >> s;
	for (int i = 0; i < 3; i++)
	{
		if (s[i]==s[i+1])
		{
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;

	//cout << ans << endl;


	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//sort(x, x + a, std::greater<ll>());

//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得
//
//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}
//
//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え


/*vector<pair<ll, ll> > hoges(a);
for (int i = 0; i < a; i++)
{
cin >> x[i];
cin >> y[i];
hoges[i] = make_pair(x[i], y[i]);
}
sort(hoges.begin(),hoges.end(),comp);
for (int i = 0; i < a; i++)
{
if (hoges[i].second>=b)
{
ans += hoges[i].first*b;
break;
}
else
{
ans += hoges[i].first*hoges[i].second;
b -= hoges[i].second;

}
}*/

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int h = sc.nextInt();

			System.out.println((a + b) * h / 2);

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 21972
n = gets.to_i
tt = 0
xx = 0
yy = 0
ok = true
n.times do
  t, x, y = gets.split.map(&:to_i)
  dist = (x - xx).abs + (y - yy).abs
  if dist > (t - tt) || (t - tt - dist) % 2 != 0
    ok = false
    break
  end
  tt = t
  xx = x
  yy = y
end
puts ok ? "Yes" : "No"


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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  if (abs(n-a) < abs(n-b)) {
    cout << "A" << endl;
  } else {
    cout << "B"<< endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	ll h;
  cin>>h; h;
  ll w;
  cin>>w; w;
  ll n;
  cin>>n; n;
	cout<<min(
						(n+h-1)/h,
						(n+w-1)/w) NL;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            String S = sc.next();
            String T = sc.next();
            int A = sc.nextInt();
            int B = sc.nextInt();
            String U = sc.next();

            if (U.equals(S)) {
                A--;
            } else {
                B--;
            }

            System.out.println(A + " " + B);
        }
    }
}


Measured memory_bytes: 26932
#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()
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll q = n / (a + b);
    ll r = n % (a + b);
    ll ans = q * a + min(a, r);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616