akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
int comp(const void *a,const void *b){
    return *(int *)a-*(int *)b;
}
int main(){
    int N;
    int a[100000];
    int i;
    int c;
    c=0;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&a[i]);
        if(a[i]!=0){
            c=1;
        }
    }
    if(c==0){
        printf("Yes");
        return 0;
    }
    if(N%3!=0){
        printf("No");
        return 0;
    }
    qsort(a,N,sizeof(int),comp);
    if(a[0]!=a[N/3-1]||a[N/3]!=a[2*N/3-1]||a[2*N/3]!=a[N-1]){
        printf("No");
        return 0;
    }
    if((int)(a[0]^a[2*N/3])==a[N/3]){
        printf("Yes");
        return 0;
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 892
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)

	a := scanNums(n + 1)
	b := scanNums(n)

	cnt := 0
	for i := 0; i < n; i++ {
		minI := int(math.Min(float64(a[i]), float64(b[i])))
		cnt += minI
		b[i] -= minI

		minI2 := int(math.Min(float64(a[i+1]), float64(b[i])))
		cnt += minI2
		a[i+1] -= minI2
	}

	fmt.Println(cnt)
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int k; 
    cin >> k;
    
    string s;
    
    cin >> s;
    string ans = "";
    char nums[s.length()+1];
    
    if(s.length() <= k){
        cout << s << "\n";
        
    }
    
    else{
        strcpy(nums, s.c_str());
        
        for(int i = 0; i < k; i++){
            ans += nums[i];
        }
        ans += "...";
        cout << ans <<"\n";
    }
    
    return 0;
}

Measured memory_bytes: 3628
n = int(input())
ans = ''
z = 0
for i in range(n):
  d1, d2 = map(int, input().split())
  if ans == '':
    if d1 == d2:
      z += 1
      if z >= 3:
        ans = 'Yes'
    else:
      z = 0
if ans == '':
  ans = 'No'
print(ans)

Measured memory_bytes: 9172
#!/usr/bin/env python3
N = int(input())
S = [sorted(input()) for _ in range(N)]
S = sorted(S)
cnt = 0
x = S[0]
cnt_all = 0
for s in S[1:]:
    if x == s:
        cnt += 1
    elif cnt > 0:
        cnt += 1
        cnt_all += int(cnt*(cnt - 1)/2)
        cnt = 0
        x = s
    else:
        x = s

cnt += 1
cnt_all += int(cnt*(cnt - 1)/2)

print(cnt_all)

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

template <class T>
class Node {
private:
  T data;
  Node<T> *prev;
  Node<T> *next;
public:
  Node() {
    data = -1;
    prev = NULL;
    next = NULL;
  }
  ~Node() {
    if (prev) {
      prev->setNext(next);
    }
    if (next) {
      next->setPrev(prev);
    }
  }
  T getData() {
    return data;
  }
  void setData(T val) {
    data = val;
  }
  Node<T> *getPrev() {
    return prev;
  }
  Node<T> *getNext() {
    return next;
  }
  void setPrev(Node<T> *node) {
    prev = node;
  }
  void setNext(Node<T> *node) {
    next = node;
  }
  void insertBefore(Node<T> *node) {
    prev = node->getPrev();
    next = node;

    node->getPrev()->setNext(this);
    node->setPrev(this);
  }
  void insertAfter(Node<T> *node) {
    prev = node;
    next = node->getNext();

    node->getNext()->setPrev(this);
    node->setNext(this);
  }
};

int main() {
  int n, x;
  bool f;
  string s;
  Node<int> *root, *first, *tmp;

  root = new Node<int>;
  root->setNext(root);
  root->setPrev(root);

  cin >> n;

  while (n--) {
    cin >> s;
    if (s == "insert") {
      cin >> x;
      tmp = new Node<int>;
      tmp->setData(x);
      tmp->insertAfter(root);
    } else if (s == "delete") {
      cin >> x;
      tmp = root;
      f = false;
      while (tmp->getNext() != root) {
        tmp = tmp->getNext();
        if (tmp->getData() == x) {
          f = true;
          break;
        }
      }
      if (f) {
        delete tmp;
      }
    } else if (s == "deleteFirst") {
      delete root->getNext();
    } else if (s == "deleteLast") {
      delete root->getPrev();
    }
  }

  tmp = root;
  while (1) {
    if (tmp->getNext() == root) {
      break;
    }
    tmp = tmp->getNext();
    if (tmp->getNext() == root) {
      cout << tmp->getData();
    } else {
      cout << tmp->getData() << ' ';
    }
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 34364
//template
import java.util.*;
import java.util.stream.Stream;
import java.io.*;
public class Main{
	static BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	
	private static final int HUNDRED = 100;
	public static void main(String[] args) throws IOException{
		
		int[] vec=readInts();
		int pow=1;
		for(int i=0;i<vec[0];i++) {
			pow*=HUNDRED;
		}
		int ans=(vec[1]+(vec[1]-1)/(HUNDRED-1))*pow;
		out.append(ans+"");
		
		out.flush();
		in.close();
		out.close();
	}
	
	public static boolean palindrome(String s) {
		boolean palindrome=true;
		int i=0,j=s.length()-1;
		while(i<j&&palindrome) {
			if(s.charAt(i++)!=s.charAt(j--))
				palindrome=false;
		}
		return palindrome;
	}
	public static long reverse(String s) {
		String aux="";
		for(int i=s.length()-1;i>=0;i--) {
			aux+=s.charAt(i);
		}
		return Long.parseLong(aux);
	}
	private static int modulo(int S, int N) { return ((S) & (N - 1)); } // returns S % N, where N is a power of 2
	private static int isPowerOfTwo(int S) { return (S & (S - 1)) == 0 ? 1 : 0; }
	private static int[] readInts() throws IOException {
		return Stream.of(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
	}
	private static int readInt() throws IOException {
		return Integer.parseInt(in.readLine());
	}
	private static long[] readLongs() throws IOException {
		return Stream.of(in.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
	}
	private static long readLong() throws IOException {
		return Long.parseLong(in.readLine());
	}
	 
}
class Pair{
	int first;
	int second;
	public Pair(int first,int second) {
		this.first=first;
		this.second=second;
	}
	public Pair() {
		
	}
}

Measured memory_bytes: 37476
#include<stdio.h>

int n, G[100][100];
int color[100], d[100], f[100], tt;

void dfs_visit(int u){
  int v;
  color[u] = 1;
  d[u] = ++tt;
  for(v = 0;v < n;v++){
    if(G[u][v] != 0){
      if(color[v] == 0){
        dfs_visit(v);
      }
    }
  }
  color[u] = 2;
  f[u] = ++tt;
} 

void dfs(){
  int u;
  for(u = 0;u < n;u++) color[u] = 0;
  tt = 0;

  for(u = 0;u < n;u++){
    if(color[u] == 0) dfs_visit(u);
  }
  for(u = 0;u < n;u++){
    printf("%d %d %d\n", u + 1, d[u], f[u]);
  }
}


int main(){
  int u, k, v, i, j;

  scanf("%d", &n);

  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      G[i][j] = 0;
    }
  }

  for(i = 0;i < n;i++){
    scanf("%d%d", &u, &k);
    for(j = 0;j < k;j++){
      scanf("%d", &v);
      G[u-1][v-1] = 1;
    }
  }

  dfs();

  return 0;
}

Measured memory_bytes: 1800
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

map<long long int, long long int> prime_factor(long long int n){
    map<long long int, long long int> res;
    for (long long int i=2; i*i<=n; i++){
        while (n%i == 0){
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

int main(int argc, char** argv){
    long long int A, B;
    cin >> A >> B;
    map<long long int, long long int> a = prime_factor(A);
    map<long long int, long long int> b = prime_factor(B);
    long long int ans = 1;
    for (auto itr = a.begin(); itr != a.end(); itr++){
        if (b[itr->first] > 0) ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>	
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vi; 
const int maxn = 2e5;
std::vector<int> G[maxn];
int h[maxn], f[maxn], vis[maxn], d[maxn];

void dfs(int u, int fa) {
	h[u] = 0;
	d[u] = d[fa] + 1;
	f[u] = fa;
	for(int i : G[u]) {
		if(i == fa) continue;
		dfs(i, u);
		h[u] = max(h[i] + 1, h[u]);
	}
}

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	int n, u, v;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> v >> u;
	d[0] = -1;
	for(int i = 0; i < n - 1; ++i) {
		int x, y;
		cin >> x >> y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs(u, 0);
	int x = (-1 + d[v]) / 2;
	int res = d[v] + h[v] - 1;
	for(int i = 0; i < x; ++i) {
		v = f[v];
		res = max(res, h[v] - 1 + d[v]);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 15104
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long a = scan.nextLong();
        long b = scan.nextLong();
        long c = scan.nextLong();
        long d = scan.nextLong();
        long ans = a * c;
        ans = Math.max(ans, a*d);
        ans = Math.max(ans, b*c);
        ans = Math.max(ans, b*d);
        System.out.println(ans);
    }
}


Measured memory_bytes: 35672
n = int(input())
a = list(map(int,input().split()))
m = min(a)
M = max(a)
mi = a.index(m)
Mi = a.index(M)
if all(a[i]<0 for i in range(n)):
    print(n-1)
    for i in range(n-2,-1,-1):
        print(i+2,i+1)
elif all(a[i]>0 for i in range(n)):
    print(n-1)
    for i in range(0,n-1):
        print(i+1,i+2)
else:
    print(2*n-1)
    if abs(M)>=abs(m):
        for i in range(0,n):
            print(Mi+1,i+1)
        for i in range(0,n-1):
            print(i+1,i+2)
    else:
        for i in range(0,n):
            print(mi+1,i+1)
        for i in range(n-2,-1,-1):
            print(i+2,i+1)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <numeric>
#include <iomanip>
#define ll long long
#define pi 3.14159265358979323846
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};
/*　BFS
 vector<vector<ll>> g(n+1);
    for(ll i = 0; i < m; i++){
        ll a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<ll> dist(n+1, -1);
    queue<ll> que;
    que.push(1);
    dist[1] = 0;
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(ll nv : g[v]){
            if(dist[nv]!=-1) continue;
            dist[nv] = dist[v]+1;
            que.push(nv);
        }
    }
*/

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    if(n%2!=0) ans = 0;
    else {
        for(ll i = 10; i <= n; i*=5)
            ans += n/i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

string a,b,c,d;

int train(string s){
    set<string> tmp;
    rep(i,s.size()-1){
        a=s.substr(0,i+1);
        b=s.substr(i+1);
        c=a;reverse(all(c));
        d=b;reverse(all(d));
        tmp.insert(a+b);
        tmp.insert(a+d);
        tmp.insert(c+b);
        tmp.insert(c+d);
        tmp.insert(b+a);
        tmp.insert(b+c);
        tmp.insert(d+a);
        tmp.insert(d+c);
        
    }
    return tmp.size();
}

int main(){
    int m;cin>>m;
    vin ans(m);
    rep(i,m){
        string s;cin>>s;
        ans[i]=train(s);
    }
    rep(i,m)cout<<ans[i]<<endl;
}


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

const int64_t mod = 1e9 + 7;

int64_t mul_mod (int64_t a, int64_t b) {
	return (a * b) % mod;
}

int n;
int64_t k;
vector < vector < int > > g;
vector < int > mul;
set < int > untouchable;

void dfs (int u, int p) {
	int cnt = 0;
	for (int v: g[u]) {
		if (v != p) {
			mul[v] = k - 1 - cnt - int((untouchable.find(v) == untouchable.end()));
			dfs(v, u);
			++cnt;
		}
	}
}

signed main () {
	cin >> n >> k;
	g.resize(n + 1);
	mul.assign(n + 1, -1);
	for (int i = 1; i < n; ++i) {
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	mul[1] = k;
	for (int v: g[1]) 
		untouchable.insert(v);
	dfs(1, -1);
	int64_t ans = 1;
	for (int i = 1; i <= n; ++i)
		ans = mul_mod(ans, int64_t(mul[i]));
	cout << ans << '\n';
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll a,b,c,d;
  	ci(a>>b>>c>>d);
  co(rM(a,b)+rM(c,d))
}

Measured memory_bytes: 256
//おまじないc++
#include <iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
int digit(long int x) {
	int d = 0;
	while (x != 0) {
		x /= 10;
		d++;
	}
	return d;
}

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

	long int m = floor(sqrt(n));
	int i;
	for (i = m; i > 0; i--) {
		if (n % i == 0) {
			break;
		}
	}
	int a = digit(i);
	int b = digit(n / i);
	cout << max(a,b );
}


Measured memory_bytes: 256
#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 << "Left" << endl;
  }
  if ((A + B) == (C + D)){
    cout << "Balanced" << endl;
  } 
  if ((A + B) < (C + D)){
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //10^19 < 9223372036854775807
typedef unsigned long long ull; //10^20 < 18446744073709551615

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

#define MOD 1000000007

int main(void)
{
    ll H,N;
    cin >> H >> N;

    int A;
    REP (i,N) {
        cin >> A;
        H -= A;
    }

   string ans = "No";
    if (H <= 0) {
        ans = "Yes";
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<cmath>
#include<array>
#include<algorithm>
//#include<deque>
#include<vector>
//#include<utility>
#include<set>
//#include<map>
//#include<list>

using namespace std;
using LLI = long long int;

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//int gcd(int x, int y) {
//	int tmp, r;
//	if (x < y) {
//		tmp = x;
//		x = y;
//		y = tmp;
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//long nCr(int n,int r) {
//	long ans = 1;
//	for (int i = n; i > n - r;i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1;i++) {
//		ans = ans / i;
//	}
//	return ans;
//}

int main(void) {
	int A, B, C, X, Y, res = 0;
	cin >> A >> B >> C >> X >> Y;
	if (A + B >= C * 2) {
		res += min(X, Y);
		X -= res;
		Y -= res;
		res = res * C * 2;
		if (A < C * 2) {
			while (X > 0) {
				res += A;
				X--;
			}
		}
		else {
			while (X > 0) {
				res += C * 2;
				X--;
			}
		}
		if (B < C * 2) {
			while (Y > 0) {
				res += B;
				Y--;
			}
		}
		else {
			while (Y > 0) {
				res += C * 2;
				Y--;
			}
		}
	}
	else {
		res += A * X + B * Y;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define I INT32_MAX
#define IM INT_MIN
#define MOD 1000000007
#define ll long long
#define lli long long int
#define rep(i,n) for (int i = 0; i < n; i++)
#define repk(i,k,n) for (int i = k; i <= n; i++)
#define repr(i,k,n) for (int i = k; i >= n; i--)
#define all(v) (v).begin(),(v).end()
typedef vector<int> vi;
typedef set<int> si;


void solve() {
	ll n;
	cin >> n;
	cout << fixed;
	cout << setprecision(10);
	vector<double> arr(n);
	for (ll i = 0; i < n; ++i)
	{
		cin >> arr[i];
	}
	double dp[n + 1][n + 1];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	for (ll i = 1; i <= n; ++i)
	{
		for (ll j = 0; j <= i; ++j)
		{
			if (j == 0) {
				dp[i][j] = dp[i - 1][j] * (1 - arr[i - 1]);
			}
			else {
				dp[i][j] = dp[i - 1][j] * (1 - arr[i - 1]) + dp[i - 1][j - 1] * (arr[i - 1]);
			}
		}
	}
	double ans = 0.0;
	for (ll i = n; i > ( n / 2); i--) {
		ans = ans + dp[n][i];
	}

	cout << ans << endl;
}

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

	int t = 1;
	// cin >> t;
	while (t--)
		solve();

}





Measured memory_bytes: 74028
import sys
sys.setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from collections import Counter
class HeapSet:
    def __init__(self):
        self.minQue = []
        self.maxQue = []
        self.counter = Counter()

    def insert(self, x):
        heappush(self.minQue, x)
        #heappush(self.maxQue, -x)
        self.counter[x] += 1

    def erase(self, x):
        self.counter[x] -= 1

    def max(self):
        while self.maxQue and self.counter[-self.maxQue[0]] == 0:
            heappop(self.maxQue)
        return -self.maxQue[0] if self.maxQue else None

    def min(self):
        while self.minQue and self.counter[self.minQue[0]] == 0:
            heappop(self.minQue)
        return self.minQue[0] if self.minQue else None

MOD = 998244353
def resolve():
    def dfs(v):
        res = 1
        for to in to_edge[v]:
            res *= dfs(to)
            res %= MOD
        return res +1

    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    AB.sort()
    st = HeapSet()
    to_edge = [[] for _ in range(N)]
    # treeを作成
    for i in range(N-1, -1, -1):
        x = AB[i][0] # 初期位置
        d = AB[i][1] # 移動距離

        while st.min() and st.min()[0] < x + d:
            to_edge[i].append(st.min()[1])
            st.erase(st.min())
        st.insert((x,i)) # 初期位置、頂点番号

    ans = 1
    for (x, v) in st.minQue:
        ans *= dfs(v)
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 315444
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll mod=INF;


int main() {
    vector<int> a(5);
    rep(i,5) cin >> a[i];
    rep(i,5){
        if (a[i]==0) cout << i+1 << endl;
    }
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n,a[110000],ci,ans;
int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	ci=1;
	fo(i,2,n+1)
		if (a[i]==a[i-1]) ci++;else{
			if (ci&1) ans++;
			ci=1;
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  /* 10^18 くらいまでいける */

int main(){
  ll a,b,k;
  cin >> a >> b >> k;

  if (k<=a){
    cout << a-k << " " << b << endl;
  }else if(k <= a+b){
    cout << 0 << " " << b - (k-a) << endl;
  }else{
    cout << 0 << " " << 0 << endl;
  }

  return 0;
}

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

int main(){
  int n,i;
  cin >> n;
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  
  vector<int> k(n,2);
  k.at(0)--;
  ll m=0,s=0;
  for(i=0;i<n-1;i++){
    if(k.at(m)==0){
      m++;
    }
    s += a.at(m);
    k.at(m)--;
  }
  
  cout << s << endl;
}

Measured memory_bytes: 5624
#include <iostream>
using namespace std;
int main(){
    int count [4][3][10];
    for (int i =0 ; i<4; i++) {
        for (int j = 0; j<3; j++) {
            for (int k = 0; k<10; k++) {
                count [i][j][k] = 0;
            }
        }
    }
    int n;
    cin >> n;
    int a,b,c,d;
    for (int l=0; l<n; l++) {
        cin >> a >> b >> c >> d;
        count [a-1][b-1][c-1] += d;
    }
    for (int x=0; x<3; x++) {
        for (int y=0; y<10; y++) {
            cout <<" "<< count [0][x][y];
        }
        cout  << endl;
    }
    for (int z= 0; z<20; z++){
        cout << "#";
    }
    cout << endl;
    for (int x=0; x<3; x++) {
        for (int y=0; y<10; y++) {
            cout << " " <<count [1][x][y];
        }
        cout  << endl;
    }
    for (int z= 0; z<20; z++){
        cout << "#";
    }
    cout << endl;
    for (int x=0; x<3; x++) {
        for (int y=0; y<10; y++) {
            cout << " " <<count [2][x][y];
        }
        cout  << endl;
    }
    for (int z= 0; z<20; z++){
        cout << "#";
    }
    cout << endl;
    for (int x=0; x<3; x++) {
        for (int y=0; y<10; y++) {
            cout << " "<< count [3][x][y];
        }
        cout  << endl;
    }
    
}



Measured memory_bytes: 3056
#include <iostream>
using namespace std;
#define rep(i,n,b) for(int i=b;i<n;i++)
int main(){
	int n;
	
	
	char mt[1000][1000];

	while( cin >> n , n){
		int ret = 0;

			rep(i,n,0)rep(j,n,0)cin >> mt[i][j];
	
		rep(i,n,0)rep(j,n,0){
		
			if(mt[i][j] == '.'){
			
				ret = max(ret,1);
				
				bool flag = true;
				rep(sz,n-max(i,j),1){
					rep(x,sz+1,0){if(mt[i+sz][j+x] == '*'){flag = false;break;}}
					rep(y,sz+1,0){if(mt[i+y][j+sz] == '*'){flag = false;break;}}
					if(!flag){break;}
					ret = max(ret,sz+1); 
				}
			}
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 1628
def isReach( goal, move, is_x):
    msum = sum(move)
    m = len(move)

    if msum < abs(goal):
        return False

    dp = [[False for _ in range(msum*2+1)] for _ in range(m+1)]
    dp[0][0] = True
    
    for i in range(m):
        for j in range(-msum,msum+1):
            if i == 0 and dp[i][j] and is_x:
                dp[i+1][j+move[i]] = True
            elif dp[i][j]:
                dp[i+1][j-move[i]] = True
                dp[i+1][j+move[i]] = True
    
    return dp[m][goal]


s = list( input().split('T') )
x,y = map( int, input().split() )

move_dist = [len(move) for move in s]
x_move = move_dist[0::2]
y_move = move_dist[1::2]

if isReach(x,x_move,True) and isReach(y,y_move,False):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 172296
//Volume5-0514
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Test {
	public int i,j,k,r;
	Test(int i,int j,int k,int r){
		this.i=i;
		this.j=j;
		this.k=k;
		this.r=r;
	}
}

class Main {

	private static ArrayList<Test> ar = new ArrayList<Test>();

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		while(true){

			int a=sc.nextInt(),
				b=sc.nextInt(),
				c=sc.nextInt();

			if(a==0&&b==0&&c==0){break;}

			int[] parts = new int[a+b+c+1];
			Arrays.fill(parts, 2);
			int   N = sc.nextInt(),
			      i,j,k,r;

			ar.clear();
			while(N-- > 0){
				i=sc.nextInt();
				j=sc.nextInt();
				k=sc.nextInt();
				r=sc.nextInt();
				ar.add(new Test(i,j,k,r));
			}

			for(Test t:ar){
				if(t.r==1){
					parts[t.i]=1;
					parts[t.j]=1;
					parts[t.k]=1;
				}
			}

			for(Test t:ar){
				if(t.r==0){
					if      (parts[t.j]==1&&parts[t.k]==1){parts[t.i]=0;}
					else if (parts[t.i]==1&&parts[t.k]==1){parts[t.j]=0;}
					else if (parts[t.i]==1&&parts[t.j]==1){parts[t.k]=0;}
				}
			}

			for(int l=1;l<parts.length;l++){
				System.out.println(parts[l]);
			}
		}
	}
}

Measured memory_bytes: 28192
#include<iostream>

int main()
{
    int K,X;
    std::cin>>K>>X;
    int max,min;
    min = X-K+1;
    max = X+K-1;
    for(int i=min;i<=max;i++){
        std::cout<<i<<' ';
    }
    std::cout<<std::endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

def main():
    N = int(input())
    A = list(map(int, input().split()))
    sumA = sum(A)//2
    B = A 
    odd = list(accumulate([0] + B[::2]+ B[1::2]))# 0+1, 2+3,...
    even = list(accumulate([0] + B[1::2]+ B[0::2]))# 1+2, 3+4,...
    # print(B,sumA)
    # print(odd)
    # print(even)
    ans = [None] * N
    for i in range(N):
        if i % 2 == 0:# evenから引く
            # print(even[N//2+i//2],even[i//2])
            ans[i] = 2*(sumA-(even[N//2+i//2]-even[i//2]))
        else:
            ans[i] = 2*(sumA-(odd[N//2+(i+1)//2]-odd[(i+1)//2]))
    print(*ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 23556
n = int(input())
li = list(map(int,input().split()))

x = 0

for i in range(n):
    if i%2 == 0:
        x += li[-i-1]
    else:
        x -= li[-i-1]

ans = [x]

tmp = x

for i in range(n-1):
    s = 2*li[i] - tmp
    ans.append(s)
    tmp = s
    
print(*ans)

Measured memory_bytes: 14092
use proconio::{input, marker::Usize1};

fn main() {
    input!(n: usize, m: usize, ab: [(Usize1, Usize1); m]);
    let mut g = vec![vec![]; n];
    for (a, b) in ab {
        g[a].push(b);
        g[b].push(a);
    }
    let mut queue = std::collections::VecDeque::from(vec![0]);
    let mut dist = vec![std::u32::MAX; n];
    dist[0] = 0;
    while let Some(x) = queue.pop_front() {
        for &y in &g[x] {
            if dist[y] == std::u32::MAX {
                dist[y] = dist[x] + 1;
                queue.push_back(y);
            }
        }
    }
    println!("Yes");
    for i in 1..n {
        let j = g[i]
            .iter()
            .copied()
            .find(|&j| dist[j] + 1 == dist[i])
            .unwrap();
        println!("{}", j + 1);
    }
}


Measured memory_bytes: 15976
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000
#define MMAX 10000

int n,a[MAX],s;
int b[MAX],t[MMAX+1];

int solve(){
  int ans=0;
  bool v[MAX];
  for(int i=0;i<n;i++){
    b[i]=a[i];
    v[i]=false;
  }
  sort(b,b+n);
  for(int i=0;i<n;i++) t[b[i]]=i;
  for(int i=0;i<n;i++){
    if(v[i]) continue;
    int cur=i;
    int S=0;
    int m=MMAX;
    int an=0;
    while(1){
      v[cur]=true;
      an++;
      int V=a[cur];
      m=min(m,V);
      S+=V;
      cur=t[V];
      if(v[cur]) break;
    }
    ans+=min(S+(an-2)*m,m+S+(an+1)*s);
  }
  return ans;
}

  
int main(){
  cin>>n;
  s=MMAX;
  for(int i=0;i<n;i++){
    cin>>a[i];
    s=min(s,a[i]);
  }
  cout<<solve()<<endl;
  return 0;
}



Measured memory_bytes: 3184
#include<stdio.h>

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int l[m];
    int r[m];
    int lmax = 0;
    int rmin = n;
    
    // l,rの最大値をそれぞれ求める
    for(int i = 0; i < m; i++) {
        scanf("%d%d", &l[i], &r[i]);
        if(rmin > r[i]) {
            rmin = r[i];
        }
        if(lmax < l[i]) {
            lmax = l[i];
        }
    }
    int count = 0;
    for(int i = 1; i <= n; i++) {
        if(lmax <= i && i <= rmin) {
            count++;
        }
    }

    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int a,b,c,d,e,f;
	while(cin>>a>>b>>c>>d>>e>>f,a+b+c+d+e+f){
		vi in(3);
		vector<pii>tmp(3);
		in[0]=a+d;in[1]=b+e;in[2]=c+f;
		int out=0;
		rep(i,3){
			out+=in[i]/3;
			tmp[i]=pii(in[i]%3,in[i]);
		}
		sort(all(tmp));
		if(tmp[0].first>0)out+=tmp[0].first;
		else if(tmp[1].first==2&&tmp[0].second>2)out++;
		cout<<out<<endl;
	}
}
 

Measured memory_bytes: 1196
#include<iostream>
 
using namespace std;
int main()
 
{
 
char a[3][3];
 
for (int i=0;i<3;i++){
    for (int j=0;j<3;j++){
        cin>>a[i][j];
    }
}
 
for(int i=0;i<3;i++){
    cout<<a[i][i];
}
 
 
return 0;
 
}

Measured memory_bytes: 256
from collections import Counter
N, M = map(int, input().split())

point = 0
answer_problems = set()
wrong_count = Counter()
for _ in range(M):
    p, s = input().split()
    
    if p in answer_problems:
        continue
    
    if s == 'AC':
        point += wrong_count[p]
        answer_problems.add(p)
    else:
        wrong_count[p] += 1

print(len(answer_problems), point)

Measured memory_bytes: 14308
#include <iostream>

int main(){
  	int m1, m2, d1, d2;
	std::cin >> m1 >> d1;
  	std::cin >> m2 >> d2;
  	if(m1 == m2) std::cout << "0" << std::endl;
  	else std::cout << "1" << std::endl;
}

Measured memory_bytes: 256
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll a,b,k;
    std::cin >> a>>b>>k;
    std::vector<ll> ans;
    
    for (int i = 100; i>=1; i--) {
        if(a %i ==0 && b %i ==0){
            ans.push_back(i);
        }
    }
    
    std::cout << ans[k-1] << std::endl;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for(auto &&x:A)cin >> x;

	bool ans = true;
	for(auto x:A){
		if( x%2==0 ){
			if(x%3!=0 && x%5!=0){
				ans = false;
			}
		}
	}
	cout << (ans? "APPROVED" : "DENIED" ) << endl;
}

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

using namespace std;

#define DIM 23
#define INF 1000000000
const long long MASKDIM = (1LL<<16) + 7;

long long a[DIM][DIM], cost[MASKDIM], dp[MASKDIM];
long long n;


int main() {
    //freopen("input.txt", "r", stdin);

    cin >> n;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) cin >> a[i][j];

    for(int mask = 0; mask < (1<<n); mask++)
        for(int b1 = 0; b1 < n; b1++)
            if(mask & (1<<b1))
                for(int b2 = b1+1; b2 < n; b2++)
                    if(mask & (1 << b2))
                        cost[mask] += a[b1][b2];

    for(int mask = 0; mask < (1<<n); mask++)
        for(int s = mask; ; s = (s-1)&mask) {
            dp[mask] = max(dp[mask], dp[mask^s] + cost[s]);
            if(s == 0) break;
        }

    cout<<dp[(1<<n)-1]<<endl;

    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_Q 100000

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N, K, Q, A[MAX_Q];
int main(int argc, char **argv) {
    cin >> N >> K >> Q;
    for(int i = 0; i < Q; ++i) {
        int a;
        cin >> a;
        A[a - 1]++;
    }

    for(int i = 0; i < N; ++i) {
       cout << (A[i] > Q - K ? "Yes" : "No") << endl;
    }
    
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;

int n;

struct node{
	int l,r;
	int key;
	void init(int a){
		l=r=-1;
		key=a;
	}
};
struct bst{
	int size;
	node t[600001];
	void init(){
		size=0;
	}
	void insert(int v){
		int i=0;
		while(i<size){
			int& child=(v<t[i].key?t[i].l:t[i].r);
			if(child==-1)child=size;
			i=child;
		}
		t[size++].init(v);
	}
	bool find(int v){
		int i=0;
		while(i<size){
			if(t[i].key==v)return true;
			int child=(v<t[i].key?t[i].l:t[i].r);
			if(child==-1)child=size;
			i=child;
		}
		return false;
	}

	void preorder(int pos){
		if(pos==-1|| pos==size)return;
		printf(" %d",t[pos].key);
		preorder(t[pos].l);
		preorder(t[pos].r);
	}

	void inorder(int pos){
		if(pos==-1|| pos==size)return;
		inorder(t[pos].l);
		printf(" %d",t[pos].key);
		inorder(t[pos].r);
	}

	void postorder(int pos){
		if(pos==-1|| pos==size)return;
		postorder(t[pos].l);
		postorder(t[pos].r);
		printf(" %d",t[pos].key);
	}
};

bst T;

int main(void){
	scanf("%d",&n);
	char str[100];
	for(int i=0;i<n;i++){
		scanf("%s",str);
		if(str[0]=='i'){
			int a;
			scanf("%d",&a);
			T.insert(a);
		}else if(str[0]=='f'){
			int a;
			scanf("%d",&a);
			printf("%s\n",T.find(a)?"yes":"no");
		}else{
			T.inorder(0);
			printf("\n");
			T.preorder(0);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 7424
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;
int main() {
    int N, M;
    cin >> N >> M;
    vector<bool> A(N+1, false);
    vector<bool> B(N+1, false);
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        if (a == 1) {
            A[b] = true;
        }
        if (b == 1) {
            A[a] = true;
        }
        if (a == N) {
            B[b] = true;
        }
        if (b == N) {
            B[a] = true;
        }
    }
    bool ans = false;
    REP(i, 2, N) {
        if (A[i] && B[i]) {
            ans = true;
        }
    }
    if (ans) {
        cout << "POSSIBLE" << endl;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<string> ab, a, b, c;
  rep(i, 0, n) {
    string s;
    cin >> s;
    if (s[0] == 'B' && s[s.size() - 1] == 'A')
      ab.push_back(s);
    else if (s[0] == 'B')
      b.push_back(s);
    else if (s[s.size() - 1] == 'A')
      a.push_back(s);
    else
      c.push_back(s);
  }

  int ai = 0, bi = 0, abi = 0;
  int as = a.size(), bs = b.size(), abis = ab.size();
  string ts = "";

  if (ai < as){
    ts += a[ai];
    ai++;
  }
  rep(i, 0, (int)ab.size()) ts += ab[i];
  if (bi < bs){
    ts += b[bi];
    bi++;
  }

  while (ai < as || bi < bs) {
    if (ai < as) {
      ts += a[ai];
      ai++;
    }

    if (bi < bs) {
      ts += b[bi];
      bi++;
    }
  }

  rep(i, 0, (int)c.size()) ts += c[i];

  int ans = 0;
  string find_word = "AB";
  string::size_type pos = ts.find(find_word);
  while (pos != string::npos) {
    ans++;
    pos = ts.find(find_word, pos + find_word.size());
  }

  cout << ans << endl;
}


Measured memory_bytes: 3888
n,k = map(int,input().split())

mod = 10**9 + 7
l = 3*10**5 + 3

M = [1]  # i!のmod
m = 1
for i in range(1, l):
    m = (m * i) % mod
    M.append(m)

def pow(x, y, mod):  # x**y の mod を返す関数
    ans = 1
    while y > 0:
        if y % 2 == 1:
            ans = (ans * x) % mod
        x = (x**2) % mod
        y //= 2
    return ans

def inv(x, mod):  # x の mod での逆元を返す関数
    return pow(x, mod-2, mod)

# print(inv(8,13))

MI = [0] * (l-1) +[inv(M[l-1], mod)]  # i!の逆元
for i in range(l-2, -1, -1):
    MI[i] = MI[i+1] * (i+1) % mod

def C(x, y):  # コンビネーション
    if y < 0 or y > x:
        return 0
    ans = M[x]
    ans = (ans * MI[y]) % mod
    return (ans * MI[x-y]) % mod

ans = 0
for i in range(min(n-1, k)+1):
    ans = (C(n,i) * C(n-1,i) + ans)%mod
print(ans)

Measured memory_bytes: 67568
H,W=map(int,input().split())
h,w=map(int,input().split())

ans=[[0]*W for _ in range(H)]

for hh in range(h):
    for i in range(W):
        ans[hh][i]=1
for ww in range(w):
    for i in range(H):
        ans[i][ww]=1

sums=0
for ll in ans:
    sums+=sum(ll)

print(H*W-sums)


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    char s[20];
    int count;
    int out=0;
    char ss[20]="CODEFESTIVAL2016";
    scanf("%s",s);
    for(count=0;s[count]!='\0';count++){
        if(s[count]=='2'){out++;}

    }
    printf("%d",out);
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        //var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var h = ToInt32(ReadLine());
        var w = ToInt32(ReadLine());
        WriteLine((num - h+1) * (num - w+1));
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


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

int main() {
  int N,M; cin >>N >>M;
  vector<pair<int,int>> AB(N);
  rep(i,0,N) {
    cin >>AB[i].first >>AB[i].second;
  }
  sort(AB.begin(),AB.end());
  ll ans=0;
  rep(i,0,N) {
    if (M>=AB[i].second) {
      M-=AB[i].second;
      ans+=ll(AB[i].first)*ll(AB[i].second);
  } else {
      ans+=ll(M)*ll(AB[i].first);
      M=0;
    }
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 3944
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
//
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
//




//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b ;
  cin >> a >> b ;
  if(a+b==3){
    cout << 3 <<endl ;
  }
  else if(a+b==5){
    cout << 1 <<endl ;
  }
  else{
    cout << 2 <<endl ;
  }
  
  
  
  return 0 ;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
 
using namespace std;
typedef long long ll;


ll ans,mx,mn,sum;
int main(){
	string s;
	cin>>s;
	sort(s.begin(),s.end());
	for(int i=0; i<s.size(); i++){
		if(s[i]!=s[i+1]){
			sum++;
			if(sum %2!=0){
				cout<<"No";
				return 0;
			}
			sum=0;
		}
		else sum++;
	}
	cout<<"Yes";
}

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

int main(){
  int D, G;
  cin >> D >> G;
  vector<int> P(D), C(D);
  rep(i, D) cin >> P.at(i) >> C.at(i);
  int ans = 1000000;
  for(int tmp = 0; tmp < (1 << D); tmp++){
    bitset<10> s(tmp);
    bool flag = true;
    int64_t sum=0;
    int n=0, middle = -1;
    for(int i = D - 1; i >= 0; i--){
      if(s.test(i)){
        n += P.at(i);
        sum += (int64_t)(P.at(i)*100*(i+1) + C.at(i));
      } else if (!s.test(i) && flag){
        n += P.at(i) - 1;
        sum += (int64_t)((P.at(i) - 1)*100*(i+1));
        flag = false;
        middle = i;
      } 
    }
    //cout << sum << ' ' << n << endl;
    
    if(sum >= G && middle != -1){
      int ml = P.at(middle) - 1;
      while(sum - 100*(middle+1) >= G && ml > 0){
        sum -= 100*(middle+1);
        ml--;
        n--;
      }
      //cout << ans << endl;
    }
    if(sum >= G) ans = min(ans, n);
    //cout << "after " << sum << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

const M: usize = 1000000007;
fn main() {
    let (n, m): (usize, usize) = util::get2();
    let mut r_lrx = vec![Vec::new(); n + 1];

    for _ in 0..m {
        let lrx: Vec<usize> = util::gets();
        r_lrx[lrx[1]].push(lrx);
    }

    let mut dp = vec![vec![vec![0; n + 2]; n + 2]; n + 2];
    dp[0][0][0] = 1;

    for i in 0..n + 1 {
        for k in 0..n + 1 {
            for j in 0..n + 1 {
                if dp[i][k][j] > 0 {
                    let r = max(max(i, k), j);
                    if r_lrx[r].iter().all(|lrx| {
                        vec![i, k, j]
                            .into_iter()
                            .map(|p| lrx[0] <= p && p <= lrx[1])
                            .map(|b| if b { 1 } else { 0 })
                            .sum::<usize>() == lrx[2]
                    })
                    {
                        let pat = dp[i][k][j];
                        dp[r + 1][k][j] = (dp[r + 1][k][j] + pat) % M;
                        dp[i][r + 1][j] = (dp[i][r + 1][j] + pat) % M;
                        dp[i][k][r + 1] = (dp[i][k][r + 1] + pat) % M;
                    } else {
                        dp[i][k][j] = 0;
                    }
                }
            }
        }
    }

    let mut sum = 0;
    for i in 0..n {
        for k in 0..n {
            sum = (sum + dp[n][i][k]) % M;
            sum = (sum + dp[i][n][k]) % M;
            sum = (sum + dp[k][i][n]) % M;
        }
    }

    println!("{}", sum);

}


Measured memory_bytes: 239868
#-*- coding: utf-8 -*-
def sol(n):
    if n <= 0: return 0
    if n == 1:
        return 0
    if n == 2:
        return 1
    x = n - 1
    if x % 2 == 0: # even
        return ((x + 1) * int(x/2))
    else: # odd
        return ((x + 1) * int(x/2)) + int((x+1)/2)



n = int(input().strip())
print (sol(n))

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

int main() {
  int N;
  cin >> N;
  int sum = 0;
  
  for (int i = 0; i < N; i++)
  {
    int l, r;
    cin >> l >> r;
    
    sum += r - l + 1;
  }
  
  cout << sum << endl;
  return 0;
}
    

Measured memory_bytes: 256
import copy

N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]
ans = 10**10
for i in range(N-1):
  x_begin, y_begin = XY[i]
  for j in range(i+1, N):
    p = XY[j][0]-XY[i][0]
    q = XY[j][1]-XY[i][1]
    c = 0
    for k in range(N-1):
      for l in range(k+1, N):
        dx = XY[k][0]-XY[l][0]
        dy = XY[k][1]-XY[l][1]
        if dx == p and dy == q or dx == -p and dy == -q:
          c += 1
    ans = min(ans, N-c)
print(ans if N > 2 else 1)

Measured memory_bytes: 3444