akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

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

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}

constexpr ll LNF = 1LL<<50;

constexpr int INF = 1e9+7;

const long double PI=3.14159265358979323846;


vector<int> dx = {1,0,-1,1,-1,0};
vector<int> dy = {1,1,1,0,0,-1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; ll k; cin >> n >> k;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];
    ll ng = -1;
    ll ok = 1e9+7;
    while(abs(ok-ng)>1ll){
        ll mid = (ok+ng)/2ll;
        int c = k;
        if(mid<=1){
            ok = 1;
            break;
        }
        rep(i,0,n){
            if(mid>=a[i]) continue;
            c -= a[i]/mid;
        }
        if(c<0){
            ng = mid;
        }
        else{
            ok = mid;
        }
    }
    cout << ok << endl;
} 

Measured memory_bytes: 4792
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

ll mod=998244353;

ll mod_pow(ll a,ll b){
	a%=mod;
	if(b==0)return 1;
	if(b==1)return a;
	ll res=mod_pow(a,b/2)%mod;
	res*=res; res%=mod;
	if(b%2)res*=a;
	return res%mod;
}

struct perm{
private:
	int sz;
	vector<ll> p,invp;
public:
	perm(int n){
		sz=n+1;
		p.resize(sz),invp.resize(sz);
		p[0]=1;
		for(int i=1;i<=sz-1;i++){
			p[i]=p[i-1]*i%mod;
		}
		invp[sz-1]=mod_pow(p[sz-1],mod-2);
		for(int i=sz-2;i>=0;i--){
			invp[i]=invp[i+1]*(i+1)%mod;
		}
	}
	ll comb(ll x,ll y){
		if(x<y||y<0)return 0;
		return (p[x]*invp[x-y]%mod)*invp[y]%mod;
	}
};
perm p(1<<20);

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll n,a,b,k; cin >> n >> a >> b >> k;
	ll ans=0;
	for(int i=0;i<=n;i++){
		if(k-a*i<0)break;
		if((k-a*i)%b)continue;
		(ans+=p.comb(n,i)*p.comb(n,(k-a*i)/b)%mod)%=mod;
	}
	cout << ans << endl;
}



Measured memory_bytes: 16640
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int x = 0;
	set<int> st;
	st.insert(0);
	rep(i, n) {
		if (s[i] == 'D') x--;
		else x++;
		st.insert(x);
	}
	cout << *rbegin(st) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(void){
    // Your code here!
    string s;
    cin >> s;
    int k=0;
    for(int i=0;i<s.size();i++){
        k += (s[i]-'0');
        k = k%9;
    }
    
    if(k==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 3720
s=input()[::-1]

count=[0]*2019
count[0]+=1
sd=0
d=1
for c in s:
   sd+=int(c)*d
   sd%=2019
   d*=10
   d%=2019
   count[sd]+=1

ans=0
for cnt in count:
    ans+=cnt*(cnt-1)//2

print(ans)



Measured memory_bytes: 9220
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>

using namespace std;

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

#define all(v) v.begin(),v.end()
#define INF 1<<30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef long long ll;

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		bool a[101][101];
		rep(i,101) rep(j,101) a[i][j] = false;

		rep(i,n){
			int m;
			cin >> m;
			rep(j,m){
				int p; cin>>p;
				a[i+1][p] = true;
			}
		}

		int k; cin>>k;
		vi b;
		rep(i,k){
			int l; cin>>l;
			b.pb(l);
		}

		int ans;
		int cnt = 0;
		rep(i,n){
			bool f = true;
			rep(j,k){
				f &= a[i+1][b[j]];
			}
			if(f){
				cnt++;
				ans = i+1;
			}
		}
		if(cnt==1){
			cout<<ans<<endl;
		}
		else{
			cout<<-1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3140
#include<iostream>

int main(void){
	int r = 0;
	int g = 0;
	int b = 0;

	std::cin >> r >> g >> b;

	if( ((r * 100) + (g * 10) + b) % 4 == 0){
		std::cout << "YES";
	}
	else
		std::cout << "NO";

	return 0;
}

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

int main(){
    vector<int> num(5, 0);
    for(int i = 0; i < 3; i++){
        int a, b;
        cin >> a >> b;
        num[a]++;
        num[b]++;
    }

    int num1 = 0, num2 = 0;
    for(int i = 1; i <= 4; i++){
        if(num[i] == 1) num1++;
        else if(num[i] == 2) num2++;
    }

    if(num1 == 2 && num2 == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;



int main(){

  int N; cin>>N;
  int A[1001];
  REP(i,N) cin>>A[i];
  int flag = 1;
  REP(i,N){
    if(A[i] % 2 == 0){
      if(A[i] % 3 != 0 and A[i] % 5 != 0) flag = 0;
      continue;
    }
  }

  auto ans = flag ? "APPROVED" : "DENIED" ;

  cout<< (flag ? "APPROVED" : "DENIED" ) <<endl;
  
  return 0;
}


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

int main() {

  int a,b,c,d,e,f;

  cin >> a;
  
  if(a==1) {
    cout<<"Hello World"<<endl;
  }
  else{
    cin>>b>>c;
    cout<<b+c<<endl;
          }

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {	
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		
		int sum = 1;
		int c = 0;
		for(;sum<b;) {
			sum += (a-1);
			c++;
		}
		
		System.out.println(c);
	}
}


Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const ld eps = 1e-9;
const db PI = atan(1) * 4;

template<typename T, typename S>inline bool upmin(T&a, const S&b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S>inline bool upmax(T&a, const S&b) { return a < b ? a = b, 1 : 0; }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
namespace SOLVE {
	void main() {
		int n;
		cin >> n;
		vector<VI> og(n, VI(3));
		vector<VI> dp(n, VI(3));

		REP(i, 0, n) {
			REP(j, 0, 3) {
				cin >> og[i][j];
			}
		}

		REP(i, 0, 3) {
			dp[0][i] = og[0][i]; // begin with itself
		}

		REP(i, 1, n) {
			REP(j, 0, 3) {
				REP(k, 1, 3) {
					dp[i][j] = max(dp[i][j], dp[i - 1][(j + k) % 3] + og[i][j]);
				}
			}
		}

		int ans = 0;
		REP(i, 0, 3) {
			ans = max(ans, dp[n - 1][i]);
		}
		cout << ans;

	}
}


signed main() {

	int t;
	//    in(t);
	t = 1;
	while (t--) {
		SOLVE::main();

	}

	return 0;
}


Measured memory_bytes: 11136
import math
a, b, h, m = map(float, input().split())
x, y = 360 / 12 * h + 360 / 12 / 60 * m, 360 / 60 * m
d = max(x, y) - min(x, y)
print('%.25f' % math.sqrt(a * a + b * b - 2 * a * b * math.cos(math.radians(d))))

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

#define MAX_N 64

char S[MAX_N];

bool X[MAX_N];

int main()
{
	scanf("%s", S);

	memset(X, 0, sizeof(X));

	int i = 0;
	for (i = 0; S[i] != '\0'; ++i) {
		X[S[i] - 'a'] = true;
	}

	if (i != 26) {
		printf("%s", S);
		int j = 0;
		for (; X[j]; ++j);
		printf("%c\n", ('a' + j));
	} else {
		int j = 25;
		for (; j > 0; --j) {
			if (S[j] > S[j - 1]) {
				break;
			}
		}
		if (j == 0) {
			printf("-1\n");
		} else {
			//printf("S[j-1]:%c\n",S[j-1]);
			for (int k = i - 1; k >= 0; --k) {
				if (S[j - 1] < S[k]) {
					S[j - 1] = S[k];
					break;
				}
			}
			S[j] = '\0';
			printf("%s\n", S);
		}
	}

	scanf("%s",S);

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;

static class Extensions
{
    public static int ToInt(this string s) => int.Parse(s);
    public static long ToLong(this string s) => long.Parse(s);
    public static char ToChar(this string s) => char.Parse(s);
    public static double ToDouble(this string s) => double.Parse(s);
    public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
    public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
    public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
    public static Queue<T> ToQueue<T>(this IEnumerable<T> seq) => new Queue<T>(seq);
    public static Stack<T> ToStack<T>(this IEnumerable<T> seq) => new Stack<T>(seq);
    public static HashSet<T> ToHashSet<T>(this IEnumerable<T> seq) => new HashSet<T>(seq);
}
static class MyMath
{
    static public long GCD(long a, long b) => (a < b) ? GCD(b, a) : ((b == 0) ? a : GCD(b, a % b));
    static public long LCM(long a, long b) => (a > b) ? (a / GCD(a, b) * b) : (b / GCD(a, b) * a);
    static private readonly long _m = 1000000000 + 7;
    static public long Mod(long val) => (val % _m + _m) % _m;
    static private long extGCD(long a, long b, ref long x, ref long y) => (b == 0) ? (a + (x = 1) * 0 + (y = 0) * 0) : (extGCD(b, a % b, ref y, ref x) + (y -= a / b * x) * 0);
    static public long ModInverse(long a, long dummy1 = 0, long dummy2 = 0) => extGCD(a, _m, ref dummy1, ref dummy2) * 0 + Mod(dummy1);    
}

class Program
{
    static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();

    static void Main()
    {
        int r = Console.ReadLine().ToInt();

        Console.WriteLine(3 * r * r);
    }
}

Measured memory_bytes: 13140
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A,B,C;
  cin>>A>>B>>C;
  int D;
  for(int i=1;i<B+1;i++){
    D=A*i%B;
    if(D==C){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;

}
     








Measured memory_bytes: 256
n = int(input())
arr = list(map(int,input().strip().split(" ")))

dp = [0]*n
dp[0] = 0
dp[1] = abs(arr[0]-arr[1])
for i in range(2,n):
    p = abs(arr[i]-arr[i-1])
    q = abs(arr[i]-arr[i-2])
    dp[i] = min(p+dp[i-1],q+dp[i-2])
print(dp[n-1])

Measured memory_bytes: 52108
using System;

class AOJ
{
	public static void Main()
	{
		var input = Console.ReadLine().Trim().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
		int c = int.Parse(input[2]);
		if(a < b && b < c){ Console.WriteLine("Yes"); }
		else{ Console.WriteLine("No"); }
	}
}

Measured memory_bytes: 19636
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	S := sc.nextStr()
	set := make(map[rune]bool)
	for _, r := range S {
		set[r] = true
	}

	if len(set) == len(S) {
		fmt.Fprintln(wtr, "yes")
	} else {
		fmt.Fprintln(wtr, "no")
	}
	wtr.Flush()
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define lli long long int
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli n,max=0;
    string s;
    cin>>n;
    map<string,int>m1;
    while(n--)
    {
        cin>>s;
        m1[s]++;
        if(m1[s]>max)
        max=m1[s];
    }
    for(auto i=m1.begin();i!=m1.end();i++)
    {
        if((i->second)==max)
        cout<<i->first<<"\n";
    }
}

Measured memory_bytes: 19252
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
   int a, b; cin >> a >> b;
   cout << max({a+b, a-b, a*b}) << ln;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=1e17;
const ll ms=(5e5)+5;


int pr[ms]={0};
int ss[ms]={0};
void check()
{
    int n=1e5;
    pr[0]=pr[1]=1;
    int i,j;
    for(i=2;i*i<=n;i++)
    {
        if(!pr[i])
        {
            for(j=i*i;j<=n;j+=i)pr[j]=1;
        }
    }
    for(i=1;i<=n;i++)
    {
        ss[i]=ss[i-1];
        if(i&1)
        {
            if(!pr[i]&&!pr[(i+1)/2])ss[i]++;
        }
    }
}


int main()
{
    idfc;
  check();
    int q;
    cin>>q;
    int l,r;


    while(q--)
    {
        cin>>l>>r;
        cout<<ss[r]-ss[l-1]<<"\n";
    }


    return 0;
}

Measured memory_bytes: 4360
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        for(;;){
            int n = sc.nextInt();
            int x = sc.nextInt();
            sc.nextLine();
            
            int cnt = 0;
            
            if (n+x == 0) break;
            
            for(int i=1;i<=n;i++){
                for(int j=1;j<=n;j++){
                    if (i==j) break;
                    for(int k=1;k<=n;k++){
                        if ((i==k) || (j==k)) break;
                        if ((i+j+k) == x) cnt++;
                    }
                }
            }
            System.out.println(cnt);
        }
    }
}


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

int main() {

	ll n, m; cin >> n >> m;
	ll ans = 0;
	if (2 * n <= m) {
		ans += n;
		m -= 2 * n;
		ans += m / 4;
	}
	else { // m < 2 * n
		ans = m / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3524
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, n, a[200600], C[200010], ans;
bool cond;
int main()
{
    //I am Monim, a tiny creature of Allah
    cin >> n;
    for(i=1;i<=n;i++)
    {
        cin >> a[i];
        if(a[i]<i)
            ans += C[i-a[i]];
        if(a[i]+i<=n)
            C[a[i]+i]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6752
# -*- coding: utf-8 -*-
from sys import stdin
a, b = [int(x) for x in stdin.readline().rstrip().split()]
res = 0
if a > b:
    res += a
    a -= 1
else:
    res += b
    b -= 1
res += a if a > b else b
print("{}".format(res))

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int d[101];
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>d[i];
  }
  sort(d,d+n);
  int cnt=1;

  int moti=d[0];
  for(int i=0;i<n;i++){
    if(moti<d[i+1]){
      moti=d[i+1];
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}


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

int main() {
    int64 N, A, B;
    cin >> N >> A >> B;
    if((B - A) % 2 == 0) {
        cout << (B - A) / 2 << '\n';
    } else {
        int64 ans = N;
        int64 a = A, b = B;
        int64 tmp = A;
        b -= a;
        a = 1;
        tmp += (b - a) / 2;
        ans = min(ans, tmp);

        a = N + 1 - B;
        b = N + 1 - A;
        tmp = a;
        b -= a;
        a = 1;
        tmp += (b - a) / 2;
        ans = min(ans, tmp);
        cout << ans << '\n';
    }
    return 0;
}


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

typedef long long LL;
using namespace std;

#define MAXN 55
#define int LL

struct inx {
	int l;
	int r;
};

inx inxs[MAXN];
int pp[MAXN * MAXN];
int qq[MAXN * MAXN];

bool operator <(inx a, inx b) {
	if (a.l == b.l) return a.r < b.r;
	return a.l < b.l;
}

signed main(){
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	int n;
	scanf("%lld", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", &inxs[i].l, &inxs[i].r);
	}
	sort(inxs, inxs + n);
	int q;
	int ans = 0;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			pp[cnt] = inxs[j].l - inxs[i].l;
			qq[cnt++] = inxs[j].r - inxs[i].r;
		}
	}
	//sort(pp, pp + cnt);
	//cnt++;
	int po1 = 0;
	int po2 = 0;
	for (int i = 0; i < cnt; i++) {
		int anx = 0;
		int p = pp[i];
		int q = qq[i];
		po1 = 0;
		po2 = 0;
		/*while (po2 < n&&po1 < n) {
			if (inxs[po2].l - inxs[po1].l > p) {
				po1++;
			}
			else if (inxs[po2].l - inxs[po1].l < p) {
				po2++;
			}
			else {
				if (po2 == po1) {
					po2++;
					continue;
				}
				if (inxs[po2].r - inxs[po1].r == q) {
					anx++;
					po1 = po2;
					po2++;
				}
				else {
					if (inxs[po2].r - inxs[po1].r < q) {
						po2++;
					}
					else {
						po1++;
					}
				}
			}
		}*/
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				if (inxs[k].l - inxs[j].l == p && inxs[k].r - inxs[j].r == q) {
					anx++;
				}
			}
		}
		ans = max(anx, ans);
	}
	printf("%lld", n - ans);
	return 0;
}


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

#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define lb(v, z) lower_bound(all(v), z)
#define ub(v, z) upper_bound(all(v), z)
#define fill(a, z) memset(a, z, sizeof(a))
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rdp(i, a, b) for (int i = (a); i >= (b); i--)
#define rlt(i, a, b) for (int i = (a); i < (b); i++)
#define cns(z) cout << z << ' '
#define cnl(z) cout << z << '\n'
#define printclock cerr<<"Time : "<<1000*(double)clock()/(double)CLOCKS_PER_SEC<<"ms\n";
#define M 1000000007
#define M2 998244353
#define MAXN 300005
#define INF 1000000000000
#define endl "\n"
#define iip(t) \
	int t;     \
	cin >> t;
#define iip2(a, b) \
	int a, b;      \
	cin >> a >> b;
#define dip(a) \
	double a;  \
	cin >> a;
#define dip2(a, b) \
	double a, b;   \
	cin >> a >> b;
#define garr(ip)       \
	for (auto &x : ip) \
		cin >> x;
#define parr(ip)          \
	for (auto &x : ip)    \
		cout << x << " "; \
	cout << endl;
#define test   \
	int _t;    \
	cin >> _t; \
	while (_t--)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vp;

int modExp(int base, int exponent, int MOD = M)
{
	if (exponent == 0)
		return 1;
	int curr = modExp(base, exponent >> 1);
	curr = (curr * curr) % MOD;
	if (exponent & 1)
		curr = (curr * base) % MOD;
	return curr;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	iip2(n, m);
	vi arr(m);
	garr(arr);
	int sum = accumulate(all(arr), 0);
	cnl(max(-1ll, n - sum));
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define MOD 1000000009
using namespace std;
typedef long long ll;
int main()
{
  int a,b;
  cin >> a >> b;
  if(a > 9 || b > 9){ cout << -1 << endl;}
  else{cout << a*b << endl;}
}


Measured memory_bytes: 256
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N,M;
    cin>>N>>M;
    set<int> food,likefood[N+1];
    int A[31][31],K[31];
    for(int i=0;i<N;i++){
        cin>>K[i];
        for(int k=0;k<K[i];k++){
            cin>>A[i][k];
            likefood[i].insert(A[i][k]);
        }
    }
    for(int i=1;i<=M;i++)food.insert(i);
    for(int i=0;i<N;i++){
        for(int f=1;f<=M;f++){
            if(likefood[i].count(f)==0){
                food.erase(f);
            }
        }
    }
    cout<<food.size()<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <deque>
#include <sstream>
using namespace std;

#define namefile ""
#define inifile freopen(namefile".inp","r",stdin); freopen(namefile".out","w",stdout)
#define fastio ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef unsigned int uint;
typedef unsigned long ulong;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
typedef vector<int> VI;
typedef vector<long> VL;
typedef vector<string> VS;
typedef vector< VI > VVI;
typedef vector< VL > VVL;
typedef vector< PII > VPII;
typedef vector< PLL > VPLL;
typedef set<int> SETI;
typedef set<long> SETL;
typedef map<int,int> MII;
typedef map<long,long> MLL;

const long long MOD = 1e9+7;
const long long INFMAX = 1e9;
const long long INFMIN = -1e9;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const double epsilon = 1e-9;
const double PI = acos(-1.00);

string s;

int res(0);

void Input()
{
    cin >> s;
}

void Solve()
{
    for (int i=0; i<s.size(); i++)
    {
        if (s[i] != s[i+1]) res++; else
        {
            if (i+3 > s.size()) res++; else res += 2;
            i += 2;
        }
    }
}

void Output()
{
    cout << res;
}

int main()
{
    fastio;
    Input();
    Solve();
    Output();
    return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int main()
  {
  string s1,s2;
  int i,j=0;
  cin>>s1;
  cin>>s2;
  for(i=0;i<3;i++)
  {
    if(s1.at(i)==s2.at(i))
      j++;
  }
cout<<j;
}


Measured memory_bytes: 256
input1 = input().split(' ')
input2 = input().split(' ')
h = int(input1[0])
n = int(input1[1])
a = input2
for i in range(n):
  h = h - (int(a[i]))
  if h <= 0:
    print('Yes')
    break
if h > 0:
  print('No')



Measured memory_bytes: 10712
from collections import deque
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    G = [[] for _ in range(N)]
    E = []
    _E = set()
    for i in range(N-1):
        a,b=mi()
        G[a-1].append(b-1)
        G[b-1].append(a-1)
        E.append((a-1,b-1))
        _E.add((a-1,b-1))
    
    leaf = 0
    for i in range(N):
        g = G[i]
        if len(g) == 1:
            leaf = i

    stack = deque([(leaf,1,None)])
    seen = set()
    path = {x:0 for x in E}
    K = 0

    def save(edge,color):
        if edge == None: return

        a,b = edge
        if (a,b) in _E:
            path[(a,b)] = color
        else:
            path[(b,a)] = color


    while stack:
        current,color,edge = stack.popleft()
        seen.add(current)
        save(edge,color)
        K = max(K,color)
        # print(current,color,edge)

        i = 1
        for next in G[current]:
            if next in seen: continue
            if color == i:
                i += 1
            
            stack.append((next,i,(current,next)))
            i += 1
    
    if N == 2:
        print(1)
        print(1)
        exit()


    print(K)
    for i in range(N-1):
        a,b = E[i]
        print(path[(a,b)],sep="")







if __name__ == "__main__":
    main()

Measured memory_bytes: 134224
n,m=map(int,input().split())
L=list(map(int,input().split()))
L.sort()
if n>=m:
  print(0)
elif m!=1:

  d=[L[i+1]-L[i] for i in range(m-1)]
  d.sort()
  d.reverse()
  ans=L[-1]-L[0]


  ans-=sum(d[:n-1])
  print(ans)
  

else:
  print(0)



Measured memory_bytes: 13968
//IN THE NAME OF GOD;
//Test By Dev-C++5.11
#include<bits/stdc++.h>
#define ll  long long
#define isc ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ld long double
#define ss string
#define ww while
#define vl vector<ll>
#define pb push_back
#define in insert
#define itr iterator
#define gt goto
#define rep(i,n,j) for(ll i=n;i<j;i++)
#define tep(i,n,j) for(ll i=n;i>=j;i--)
#define co(n) cout << n ;
#define pll pair<ll,ll>
#define bft bool f=true
#define bff bool f=false
using namespace std;

ll bmm(ll a, ll b) {
	if (b == 0) return a;
	else return bmm(b, a%b);
}
ll kmm(ll a, ll b) {
	return(a*b) / bmm(a, b);
}

const ll mod = 1e9 + 7;
const ll MAXN = 2e5+5;

ll n;

int main() {
	isc;
	cin >> n;
	rep(i,1,10){
		rep(j,1,10){
			if(i*j==n){
				cout << "Yes";
				gt onja;
			}
		}
	}
	cout << "No";
	onja:
		cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

#define MAX 10000
#define NIL -1

struct Node { int parent, left, right;};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d) {
	if(u == NIL) return;
	D[u] = d;
	setDepth(T[u].left, d+1);
	setDepth(T[u].right,d+1);
}

int setHeight(int u) {
	int h1 = 0, h2 = 0;
	if(T[u].left != NIL)
		h1 = setHeight(T[u].left)  + 1;
	if(T[u].right != NIL)
		h2 = setHeight(T[u].right) + 1;
	return H[u] = (h1 > h2 ? h1 : h2);
}

// 接点 u の兄弟を返す
int getSibling(int u) {
	if( T[u].parent == NIL ) return NIL;
	if(T[T[u].parent].left != u && T[T[u].parent].left != NIL )
		return T[T[u].parent].left;
	if(T[T[u].parent].right != u && T[T[u].parent].right != NIL )
		return T[T[u].parent].right;
	return NIL;
}

void print(int u) {
	printf("node %d: ",u);
	printf("parent = %d, ",T[u].parent);
	printf("sibling = %d, ",getSibling(u));
	int deg = 0;
	if(T[u].left  != NIL) deg++;
	if(T[u].right != NIL) deg++;
	printf("degree = %d, ",deg);
	printf("depth = %d, ",D[u]);
	printf("height = %d, ",H[u]);
	
	if(T[u].parent == NIL) {
		printf("root\n");
	} else if(T[u].left == NIL && T[u].right == NIL) {
		printf("leaf\n");
	} else {
		printf("internal node\n");
	}
}

int main(void) {
	int v, l, r, root = 0;
	scanf("%d",&n);
	for(int i=0;i<n;i++) T[i].parent = NIL;
	for(int i=0;i<n;i++) {
		scanf("%d %d %d",&v,&l,&r);
		T[v].left  = l;
		T[v].right = r;
		if(l != NIL) T[l].parent = v;
		if(r != NIL) T[r].parent = v;
	}
	
	for(int i=0; i<n; i++)
	if(T[i].parent == NIL) root = i;
	
	setDepth(root,0);
	setHeight(root);
	
	for(int i=0;i<n;i++) print(i);
	
	return 0;
}



Measured memory_bytes: 2736
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define MOD 1000000007
#define fast ios_base::sync_with_stdio(false)
#define itt cin.tie(0)
#define now cout.tie(0)
using namespace std;
ll n;
vector<pair<ll,ll> > vp,vn;
string s;
int main(){
	fast;itt;now;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		ll mn=1e18,pre=0;
		for(int j=0;j<s.size();j++){
			if(s[j]=='(') pre++;
			else pre--;
			mn=min(mn,pre);
		}
		if(pre>=0) vp.push_back(make_pair(mn,pre));
		else vn.push_back(make_pair(mn,pre));
	}
	sort(vp.begin(),vp.end());
	sort(vn.begin(),vn.end());
	ll pre=0;
	bool cn=true;
	for(int i=vp.size()-1;i>=0;i--){
		if(pre+vp[i].F<0) cn=false;
		pre+=vp[i].S;
		if(!cn) break;
	}
	if(!cn){
		puts("No");
		return 0;
	}
	int i=0,j;
	for(j=1;j<=vn.size();j++){
		if(j==vn.size()){
			pre+=vn[i].S;
			break;
		}
		ll x1=pre+vn[i].S;
		ll x2=pre+vn[j].S;
		ll d1=vn[j].F+x1;
		ll d2=vn[i].F+x2;
		if(d1<0&&d2<0) cn=false;
		else if(d1<d2) pre+=vn[j].S;
		else pre+=vn[i].S,i=j;
		if(pre<0) cn=false;
		if(!cn) break;
	}
	if(pre!=0) cn=false;
	if(!cn) puts("No");
	else puts("Yes");
	return 0;
}

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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define int ll
//#define endl '\n'

int n;

int32_t main()
{
    IOS
    cin>>n;
    for (int i=0;i<=20;i++)
    {
        if ((1<<i)==n)
        {
            return cout<<"No"<<endl,0;
        }
    }
    cout<<"Yes"<<endl;
    cout<<"1 2\n2 3\n";
    cout<<n+1<<' '<<n+2<<'\n';
    cout<<n+2<<' '<<n+3<<'\n';
    cout<<3<<' '<<n+1<<'\n';
    for (int i=5;i<=n;i+=2)
    {
        cout<<i-1<<' '<<i<<'\n';
        cout<<i<<' '<<n+1<<'\n';
        cout<<n+1<<' '<<n+i-1<<'\n';
        cout<<n+i-1<<' '<<n+i<<'\n';
    }
    if (n%2==0)
    {
        cout<<n<<' '<<n-1<<endl;
        int now=((n-1)^n^1);
        cout<<now+n<<' '<<2*n<<endl;
    }
}



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

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int score = 0;
    rep(i,n-1) if(s[i]==s[i+1]) score++;
    int ans = min(score + 2 * k, n-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
import math

n = int(input())
s = input()
count = 0

rCount = s.count("R")
gCount = s.count("G")
bCount = s.count("B")
ans = rCount * gCount * bCount

for dis in range(1, math.ceil(len(s) / 2)):
    for i in range(dis, len(s) - dis):
        if s[i-dis] != s[i] and s[i-dis] != s[i+dis] and s[i] != s[i+dis]:
            ans -= 1
print(ans)

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

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

    vector<ll> mX(N), mY(N);
    rep(i, N) {
        mX[i] = X[i] + Y[i];
        mY[i] = X[i] - Y[i];
    }

    sort(mX.begin(), mX.end());
    sort(mY.begin(), mY.end());

    cout << max(mX[N - 1] - mX[0], mY[N - 1] - mY[0]) << endl;
}

Measured memory_bytes: 9592
n, t = map(int, input().split())

ct = []
for i in range(n):
    ct.append(list(map(int, input().split())))

c = []
for i in range(n):
    if ct[i][1] <= t:
        c.append(ct[i][0])

if c == []:
    print("TLE")
else:
    c.sort()
    print(c[0])


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)

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

   string s,t;
   cin>>s>>t;
   int n=s.length();
   int ch=0;
   for(int i=0;i<n;++i)
   {
       if(s[i]==t[0])
       {
           int c=1;
           for(int j=0;j<n;++j)
           {
               if(t[j]!=s[(i+j)%n]){c=0;}
           }
           if(c){ch=1;}
       }
   }
   if(ch)
   {
       cout<<"Yes";
   }
   else
   {
       cout<<"No";
   }

return(0);
}


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

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			String[] arr = str.split(" ");
			
			int W = Integer.parseInt(arr[0]);
			int H = Integer.parseInt(arr[1]);
			int x = Integer.parseInt(arr[2]);
			int y = Integer.parseInt(arr[3]);
			int r = Integer.parseInt(arr[4]);
			
			if((x >= r && y >= r) && (x + r <= W && y + r <= H)) System.out.println("Yes");
			else System.out.println("No");
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}

	}
}

Measured memory_bytes: 17092
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>

using namespace std;

long long result, n,m;

long long total[2] = {};

long long a[100000] = {};

int main() {

	cin >> n >> m;
	
	result = (n-2)*(m-2);

	if (n == 1 && m == 1) {
		result = 1;
	}

	if (n == 1 && m!=1) {
		result = m - 2;
	}

	if (n!= 1 && m == 1) {
		result = n - 2;
	}

	cout << result << endl;

return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1e-9;

void Main(int argc, char** argv) {
    int x, y;
    cin>>x>>y;
    int ans = 0;
    if (x ==3) {
        ans += 100000;
    }
    if (x ==2) {
        ans += 200000;
    }
    if (x ==1) {
        ans += 300000;
    }
    if (y ==3) {
        ans += 100000;
    }
    if (y ==2) {
        ans += 200000;
    }
    if (y ==1) {
        ans += 300000;
    }
    if (x == 1 && y == 1) {
        ans += 400000;
    }
    cout << ans << endl;
}

signed main(int argc, char** argv) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main(argc, argv);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<cstdlib>
#include<ctime>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N = 1000;

int rectsum(int y1,int x1,int y2,int x2,int sum[N+1][N+1]){
  int ret = sum[y2+1][x2+1];
  ret -= sum[y2+1][x1];
  ret -= sum[y1][x2+1];
  ret += sum[y1][x1];
  return ret;
}

void rectsumPrecalc(int r,int c,int inp[N][N],int sum[N+1][N+1]){
  rep(i,r+1)rep(j,c+1)sum[i][j] = 0;
  rep(i,r){
    rep(j,c){
      sum[i+1][j+1]  = inp[i][j];
      sum[i+1][j+1] += sum[i+1][j];
      sum[i+1][j+1] += sum[i][j+1];
      sum[i+1][j+1] -= sum[i][j];
    }
  }
}

int bf(int y1,int x1,int y2,int x2,int inp[N][N]){
  int sum = 0;
  REP(i,y1,y2+1)REP(j,x1,x2+1)sum += inp[i][j];
  return sum;
}

void test(){
  int r = 1000,c=1000;
  static int inp[N][N];
  static int sum[N+1][N+1];
  rep(i,r){
    rep(j,c){
      inp[i][j] = rand()%100;
    }
  }
  rectsumPrecalc(r,c,inp,sum);
  rep(i,1000){
    int y1 = rand()%r,y2=rand()%r;
    if (y1 > y2)swap(y1,y2);
    int x1 = rand()%c,x2 = rand()%c;
    if (x1 > x2)swap(x1,x2);
    assert(rectsum(y1,x1,y2,x2,sum) == bf(y1,x1,y2,x2,inp));
  }
}


int inp[3][N][N];
int sum[3][N+1][N+1];
main(){
  int r,c,q;
  while(cin>>r>>c>>q){
    string in;
    rep(i,r)rep(j,c)rep(k,3)inp[k][i][j] = 0;
    rep(i,r){
      cin>>in;
      rep(j,c){
	int ind = 2;
	if (in[j] == 'J')ind=0;
	else if (in[j] == 'O')ind = 1;
	inp[ind][i][j]++;
      }
    }
    rep(i,3)rectsumPrecalc(r,c,inp[i],sum[i]);
    rep(i,q){
      int y1,x1,y2,x2;
      cin>>y1>>x1>>y2>>x2;
      y1--;x1--;y2--;x2--;
      rep(j,3){
	if (j)cout <<" " ;
	cout << rectsum(y1,x1,y2,x2,sum[j]);
      }
      cout << endl;
    }
  }
}

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

using namespace std;

const int N = 305;

int md;

inline void add(int &x, int y) {
  x += y;
  if (x >= md) x -= md;
}

inline void sub(int &x, int y) {
  x -= y;
  if (x < 0) x += md;
}

inline int mul(int x, int y) {
  return 1ll * x * y % md;
}

inline int power(int b, int p) {
  int r = 1;
  while (p > 0) {
    if (p & 1) r = mul(r, b);
    b = mul(b, b);
    p >>= 1;
  }
  return r;
}

int dp[N][N];
int pref[N][N];
int ch[N][N];

void precalc() {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0) {
        ch[i][j] = 1;
      } else {
        add(ch[i][j], ch[i - 1][j]);
        add(ch[i][j], ch[i - 1][j - 1]);
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k >> md;
  precalc();
  for (int i = 0; i <= k; i++) dp[0][i] = 1;
  for (int i = 1; i <= n; i++) {
    pref[i - 1][0] = 0;
    for (int j = 1; j <= k; j++) {
      add(pref[i - 1][j], pref[i - 1][j - 1]);
      add(pref[i - 1][j], dp[i - 1][j - 1]);
      for (int r = 1; r <= i; r++) {
        add(dp[i][j], mul(ch[i - 1][r - 1], mul(pref[r - 1][j], dp[i - r][j])));
      }
    }
  }
  cout << dp[n][k] << '\n';
  return 0;
}


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

void solve(int A, int L) {
    map<int, int> cnt;
    cnt[A] = 1;
    for (int i = 2; i <= 21; i++) {
        vector<int> digits(L);
        for (int j = 0; j < L; j++) {
            digits[j] = A % 10;
            A /= 10;
        }
        sort(digits.begin(), digits.end());
        int min_a = 0, max_a = 0;
        int mul_num = 1;
        for (int j = L - 1; j >= 0; j--) {
            min_a += digits[j] * mul_num;
            mul_num *= 10;
        }
        reverse(digits.begin(), digits.end());
        mul_num = 1;
        for (int j = L - 1; j >= 0; j--) {
            max_a += digits[j] * mul_num;
            mul_num *= 10;
        }
        A = max_a - min_a;
        if (cnt[A] > 0) {
            cout << cnt[A] - 1 << ' ' << A << ' ' << i - cnt[A] << endl;
            return;
        }
        cnt[A] = i;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a0, L;
    while (true) {
        cin >> a0 >> L;
        if (a0 == 0 && L == 0) break;
        solve(a0, L);
    }
    return 0;
}


Measured memory_bytes: 3132
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    d = collections.defaultdict(int)
    for i in range(m):
        d[int(readline())]
    dp = [0] * (n + 1)
    dp[0] = 1
    for i in range(1, n + 1):
        if i not in d:
            if i == 1:
                dp[i] += dp[i-1]
            else:
                dp[i] += dp[i-1]
                dp[i] += dp[i-2]
            dp[i] %= mod
    print(dp[-1])


if __name__ == '__main__':
    solve()


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

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

    if((a+b)%2 == 0){
        int k = (a+b)/2;
        cout << k << endl;
    }else { 
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

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

typedef long long lli;
typedef vector<int> Vi;
typedef vector<lli> Vl;
typedef pair<int, int> Pii;
typedef pair<lli, lli> Pll;


//===

const int MOD = (int)1e9 + 7;


int main()
{
	int N, X;
	cin >> N >> X;
	vector<int> S(N);
	for (int i = 0; i < N; ++i) cin >> S[i];

	sort(S.begin(), S.end());

	vector<Vl> dp(N + 1, Vl(X + 1));
	for (int x = 0; x <= X; ++x) dp[0][x] = x;

	for (int i = 0; i < N; ++i) {
		for (int x = 0; x <= X; ++x) {
			dp[i + 1][x] = (dp[i][x % S[i]] + i * dp[i][x]) % MOD;
		}
	}

	cout << dp[N][X] << endl;
}

Measured memory_bytes: 158592
import java.util.Scanner;
import java.util.ArrayList;


public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int num1 = scan.nextInt();
        int num2 = scan.nextInt();
        int num3 = scan.nextInt();
        int max = num1+num2;
        if(max > num1 + num3)   max = num1 + num3;
        if(max > num2 + num1)   max = num2 + num1;
        if(max > num2 + num3)   max = num2 + num3;
        if(max > num3 + num1)   max = num3 + num1;
        if(max > num3 + num2)   max = num3 + num2;

         
        System.out.println(max);
    }
}

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

const int MAX = 1000000;

int main() {
	bool prime[MAX + 1];
	int sum[MAX + 1];
	fill(prime, prime + MAX + 1, true);
	fill(sum, sum + MAX + 1, 0);
	prime[0] = prime[1] = false;
	for(int i = 2; i <= MAX; i++) {
		sum[i] = sum[i - 1];
		if(prime[i]) {
			sum[i]++;
			for(int j = 2 * i; j <= MAX; j += i)
				prime[j] = false;
		}
	}
#if 0
	for(int i = 1; i < 20; i++) {
		cout << i << " " << sum[i] << endl;
	}
#endif
	for(int n; cin >> n;)
		cout << sum[n] << endl;
	return 0;
}

Measured memory_bytes: 0
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        p: [(String, i32); n],
    }
    let mut z = vec![];
    for (i, &(ref s, v)) in p.iter().enumerate() {
        z.push((s, -v, i + 1));
    }
    z.sort();
    for (_, _, k) in z {
        println!("{}", k);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<string> tp(2 * N);
	vector<int> a(2 * N);
	vector<int> inv_w(N), inv_b(N);
	for (int i = 0; i < 2 * N; ++i) {
		cin >> tp[i] >> a[i]; --a[i];
		if (tp[i] == "W") inv_w[a[i]] = i;
		if (tp[i] == "B") inv_b[a[i]] = i;
	}
	vector<vector<int> > sw(N + 1, vector<int>(2 * N + 1)), sb(N + 1, vector<int>(2 * N + 1));
	for (int i = 0; i < N; ++i) {
		++sw[i][inv_w[i]];
		++sb[i][inv_b[i]];
	}
	for (int i = N - 1; i >= 0; --i) {
		for (int j = 2 * N - 1; j >= 0; --j) {
			sw[i][j] += sw[i + 1][j];
			sb[i][j] += sb[i + 1][j];
		}
	}
	for (int i = N - 1; i >= 0; --i) {
		for (int j = 2 * N - 1; j >= 0; --j) {
			sw[i][j] += sw[i][j + 1];
			sb[i][j] += sb[i][j + 1];
		}
	}
	vector<vector<int> > dp(N + 1, vector<int>(N + 1, 1 << 30));
	dp[0][0] = 0;
	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j <= N; ++j) {
			if (i >= 1) {
				int ptr = inv_w[i - 1], cost = 0;
				cost += sw[i][0] - sw[i][ptr];
				cost += sb[j][0] - sb[j][ptr];
				dp[i][j] = min(dp[i][j], dp[i - 1][j] + cost);
			}
			if (j >= 1) {
				int ptr = inv_b[j - 1], cost = 0;
				cost += sw[i][0] - sw[i][ptr];
				cost += sb[j][0] - sb[j][ptr];
				dp[i][j] = min(dp[i][j], dp[i][j - 1] + cost);
			}
		}
	}
	cout << dp[N][N] << endl;
	return 0;
}

Measured memory_bytes: 78848
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))

# cumsum
s = [0]*(N+1)
for i in range(N):
  s[i+1] = s[i]+A[i]

# dic
dic = defaultdict(int)
for i in range(N+1):
  dic[s[i]] += 1
# ans
ans = 0
for k, v in dic.items():
  ans += v*(v-1)//2 # aCb
print(ans)  


Measured memory_bytes: 41672