akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


int main(){
    int N,X;
    cin >> N >> X;
    vector<int>vec(N);
    for(int i=0;i<N;i++){
        cin >> vec.at(i);
    }
    int count = 0;
    
    int s=0;


    for(int i=0;i<N+1;i++){
        if(s <= X){
            count++;
        }
        if(i != N){
            s += vec.at(i);
        }
    }
    cout << count <<endl;
}


Measured memory_bytes: 256
from collections import defaultdict

N = int(input())

cnts = defaultdict(int)
for i in range(1, N + 1):
    if i % 10 == 0:
        continue
    digits = []
    while i > 0:
        i, r = divmod(i, 10)
        digits.append(r)
    digits = digits[::-1]
    cnts[(digits[0], digits[-1])] += 1

ans = 0
for (head, tail), c1 in cnts.items():
    c2 = cnts.get((tail, head), 0)
    ans += c1 * c2
print(ans)


Measured memory_bytes: 9448
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String s = scan.next();
		char[] c = new char[n];
		int countR = 0;
		int ans = 0;
		
		for(int i=0;i<n;i++) {
			c[i] = s.charAt(i);
			if(c[i] == 'R') {
				countR++;
			}
		}
		
		for(int i=0;i<countR;i++) {
			if(c[i] == 'R') {
				continue;
			}else {
				ans++;
			}
		}
		System.out.println(ans);

	}

}

Measured memory_bytes: 40980
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        for (int i = -k+1; i <= k-1; i++) {
            System.out.print(x+i + " ");
        }
        System.out.println("");
    }
}

class io{

    public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    }
    public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    }
}

class Algo{
    public static boolean isOdd(int n){
        return n % 2 == 1;
    }
    public static boolean isEven(int n){
        return n % 2 == 0;
    }


}



Measured memory_bytes: 21844
from fractions import gcd
n,k = map(int,input().split())
a = list(map(int,input().split()))
g = a[0]
for i in range(n):
  g = gcd(g,a[i])
if k%g == 0 and k <= max(a):
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Measured memory_bytes: 88812
using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        string s = sc.Next();

        int n = s.Length;
        long[] dp = new long[2019];
        long ans = 0;
        for (int i = 0; i < n; i++)
        {
            int c = s[i] - '0';
            var next = new long[2019];
            next[c] += 1;
            for (int j = 0; j < 2019; j++)
            {
                next[(j * 10 + c) % 2019] += dp[j];
            }
            
            ans += next[0];
            dp = next;
        }
        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 45160
#include "bits/stdc++.h"
#define pb push_back
#define mt make_tuple
#define all(a) (a).begin(),(a).end()
#define frep(i,a,n) for(int i=(a);i<(n);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define rrep(i, n) for(int i=n-1;i>=0;--i)
#define debug(x) cout << #x << " : " << x << " ------------ " << endl;
using namespace std;
int main()
{
    string d;
    while (cin >> d, d != "#") {
        auto rit = d.rbegin();
        vector<int> nw;
        while (rit != d.rend()) {
            if (*rit == 'n') nw.pb(-1);
            else if (*rit == 'w') nw.pb(1);
            ++rit;
        }
        
        int a = nw[0] > 0 ? 90 : 0, b = pow(2, nw.size() - 1);
        frep(i, 1, nw.size()) {
            a = 2 * a + 90 * nw[i];
        }
        
        while (a > 0 && b > 1 && a % 2 == 0) {
            a /= 2;
            b /= 2;
        }
        
        cout << a;
        if (b > 1) cout << "/" << b;
        cout << endl;
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3280
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Q = MAP()

event = [None]*(2*N+Q)
Xl = [0]*N
for i in range(N):
    S, T, X = MAP()
    event[2*i] = (S-X, 1, X)
    event[2*i+1] = (T-X, 0, X)
    Xl[i] = X

t = 2*N
for i in range(Q):
    D = INT()
    event[t+i] = (D, 2, 0)


event.sort()
p = []
q = []
for t, c, x in event:
    if c == 0:
        heappush(q, x)
    elif c == 1:
        heappush(p, x)
    else:
        while q and p[0] == q[0]:
            heappop(p)
            heappop(q)
        print(-1 if not p else p[0])


Measured memory_bytes: 86228
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    while (true) {
      String str = scan.nextLine();
      int sum = 0;

      if (str.equals("0")) {
        break;
      }

      for (int i = 0; i < str.length(); i++) {
        char ch = str.charAt(i);
        sum += Character.getNumericValue(ch);
      }
      
      System.out.println(sum);
    
    }

  }

}


Measured memory_bytes: 26596
#include<iostream>
#include<cstring>
using namespace std; 
string a,b="CF"; 
int al,bl;
int main()
{
    getline(cin,a);
    al=a.length();
    for(int i=0;i<al;i++)
        if(a[i]==b[bl])
		{
            bl++;
            if(bl==2)   
                break;
        }
    if(bl==2)
		cout<<"Yes"; 
    else 
		cout<<"No";
    cout<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int n,m,dumy=0,a,b;
	cin>>n>>m;
	int x[n];
	for(int i=0;i<n;i++)
	x[i]=i+1;
	for(int i=0;i<m;i++){
		scanf("%d,%d",&a,&b);
		swap(x[a-1],x[b-1]);
	}
	for(int i=0;i<n;i++)
	cout<<x[i]<<endl;
	return 0;
}

Measured memory_bytes: 1240
// Contest: AtCoder Beginner Contest 173 (https://atcoder.jp/contests/abc173)
// Problem: A: Payment (https://atcoder.jp/contests/abc173/tasks/abc173_a)


// region boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion

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

    int n; cin >> n;
    int x = (n + 999) / 1000;
    cout << (1000 * x - n) << '\n';

    return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100000

int h,t,A1[N];
char A2[N][10];

void enqueue(char *l, int q)
{
  int i = 0;

  
  if(isFull()){
    fprintf(stderr,"overflow!\n");
    exit(2);
  }

  
  A1[t] = q;
  strcpy(A2[t],l);
  if(t + 1 == N) t = 0;
  else t++;
}

int dequeue()
{
  int f;

  if(isEmpty()){
    fprintf(stderr,"underflow!\n");
    exit(1);
  }

  f = h;
  if(h + 1 == N) h = 0;
  else h++;

  
  return f;
}

int isEmpty()
{
  return h == t;

}

int isFull()
{
  return h == (t + 1) % N;
}

void roundschedule(int d, int b)
{
  int i,num,s;
  int total = 0;
  char B[10];



  for(i=0;i<d;i++){
    scanf("%s%d",B,&num);
    enqueue(B,num);
  }

  while(!isEmpty()){
    num = dequeue();
    if(b>=A1[num]){
      total += A1[num];
      printf("%s %d\n",A2[num],total);
    }

    else{
      s = A1[num] - b;
      total += b;
      enqueue(A2[num],s);
    }
  }
}

int main()
{
  int n,m;

  scanf("%d%d",&n,&m);
  roundschedule(n,m);

  return 0;
}



Measured memory_bytes: 3112
import java.util.*;
import javax.lang.model.util.ElementScanner6;
import java.lang.Math;

public class Main {

    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);

        // 入力
        int k = sc.nextInt();
        String s = sc.next();

        // 処理
        String out = "";
        if(s.length() <= k){
            out = s;
        } else {
            out = s.substring(0, k).concat("...");
        }

        // 出力
        System.out.println(out);
    }
}


Measured memory_bytes: 35816
fun main(args: Array<String>) {
  val N = readInt()
  val XY = (1..N).map {
    val A = readInt()
    (1..A).map { readInts() }
  }

  var max = 0
  for (i in 0 until N) {
    var TFN = arrayOfNulls<Boolean>(N)
    for (i in 0 until i) TFN[i] = false

    fun assume(n: Int, tf: Boolean): Boolean {
      if (TFN[n] != null) {
        return TFN[n] == tf
      }
      TFN[n] = tf
      if (tf) {
        XY[n].forEach {
          val x = it[0]
          val y = it[1] == 1
          if (!assume(x - 1, y)) return false
        }
      }
      return true
    }
    for (j in i until N) {
      val tmp = TFN.copyOf()
      if (assume(j, true)) {
        continue
      }
      TFN = tmp
      assume(j, false)
    }
    val sum = TFN.count { it == true }
    max = Math.max(max, sum)
  }

  println(max)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(' ')
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 38368
using System;    
     
class sample12{    
    static void Main(string[] args){
        int i ;
        int count = 0;
        int[] compared_number = new int[3];
        string[] str_number = Console.ReadLine().Split(' '); 
        
        //入力された数字をintへ変換
        for(i = 0 ; i < 3; i++){
                    compared_number[i] = int.Parse(str_number[i]);
        }
        
        //バリデーション
        if(compared_number[0] > compared_number[1]){ 
                    Console.WriteLine("bにはa以上の数字を入力してください。"); 
                    Environment.Exit(0);
                    
        }else if(compared_number[0] < 1 || compared_number[1] < 1 || compared_number[2] < 1 || compared_number[0] > 10000 || compared_number[1] > 10000 || compared_number[2] > 10000 ){
            
                    Console.WriteLine("入力した値は範囲外です。");
                    Environment.Exit(0);
        } 
                
        //約数ならカウントする
        for(i = compared_number[0]; i < (compared_number[1]+ 1); i++){
            if(compared_number[2] %i == 0){
                count++;
            }
        }
        Console.WriteLine(count);
    }    
}   


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



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

    for(int i=0;i<N;){
        count++;
        if(i==N-1)break;
        if(data.at(i+1)>data.at(i)){
            for(;i<N;){
                if(i==N-1)break;
                if(data.at(i+1)>=data.at(i))i++;
                else break;
            }
        }else
        
         if(data.at(i+1)<data.at(i)){
            for(;i<N;){
                if(i==N-1)break;
                if(data.at(i+1)<=data.at(i))i++;
                else break;
            }
        }else{
            i++;
            count--;
            continue;
        } 
        i++;
        
        
    }
    cout<<count<<endl;

}
    



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

#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

using namespace std;
ll power(ll a,ll n)
{
          ll result=1;
          while(n>0)
          {
               if(n&1)
                    result=result*a;
               a=a*a;
               n=n>>1;
          }
          return result;
}
ll lcm(ll a,ll b)
{
          return ((a*b)/__gcd(a,b));
}
bool ispow2(ll n)
{
          return (ceil(log2(n))==floor(log2(n)));
}
bool isprime(ll n)
{
          if(n==1)
               return false;
          else if(n==2)
               return true;
          else
          {
               for(ll i=2;i*i<=n;++i)
               {
                    if(n%i==0)
                         return false;
               }
               return true;
          }
}

ll ncr(ll n,ll r)
{
    if(r > n - r)
          r = n - r;
    ll ans = 1;
    ll i;

    for(i = 1; i <= r; i++)
     {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
void sieve(int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
     prime[1]=false;
     prime[0]=false;
    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout<<p<<" ";
}
ll findProductSum(ll A[], int n)
{
    ll array_sum = 0;
    for (int i = 0; i < n; i++)
        array_sum = (array_sum + A[i])%MOD;


    ll array_sum_square = ((array_sum%MOD) * (array_sum%MOD))%MOD;

    ll individual_square_sum = 0;
    for (int i = 0; i < n; i++)
        individual_square_sum  = (individual_square_sum + ((A[i]%MOD)*(A[i]%MOD))%MOD)%MOD;

     ll a = array_sum_square%MOD;
     ll b = individual_square_sum%MOD;

     ll temp = (((a-b+MOD)%MOD)+MOD)%MOD;
     return temp/2;
    //return (((MOD + array_sum_square - individual_square_sum)%MOD)/2)%MOD;
}
int main()
{
          ios_base::sync_with_stdio(0);
          cin.tie(0);

          int t=1;
          //cin>>t;
          while(t--)
          {
                    int n;
                    cin>>n;
                    ll a[n];
                    for(int i=0;i<n;++i)
                         cin>>a[i];
                    ll ans=0;
                    ll sum=0;
                    for(int i=0;i<n;++i)
                    {
                         ans = (ans + (a[i]*sum)%MOD)%MOD;
                         sum = (sum +a[i])%MOD;
                    }
                    cout<<ans;
          }
          return 0;
}


Measured memory_bytes: 5152
# D - String Formation

from collections import deque

S = str(input())
Q = int(input())

que = deque()
for s in S:
    que.append(s)

is_reverse = False

for _ in range(Q):
    query = [q for q in input().split()]
    t = int(query[0])
    if t == 1:
        is_reverse = not is_reverse
    elif t == 2:
        f, c = int(query[1]), str(query[2])
        if f == 1:
            if not is_reverse:
                que.appendleft(c)
            else:
                que.append(c)
        elif f == 2:
            if not is_reverse:
                que.append(c)
            else:
                que.appendleft(c)

if not is_reverse:
    ans = ''.join(list(que))
else:
    ans = ''.join(reversed(list(que)))

print(ans)


Measured memory_bytes: 10220
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	m,k = readline() |> split |> parseMap
	if k>=2^m
		println(-1)
	elseif m == 0
		println("0 0")
	elseif m==1 && k==0
		println("0 0 1 1")
	elseif m==1 && k==1
		println(-1)
	else
		for i in 0:2^m-1
			if i!=k
				print(i," ")
			end
		end
		print(k, " ")
		for i in 1:2^m
			if 2^m-i!=k
				print(2^m-i," ")
			end
		end
		println(k)
	end
end

main()

Measured memory_bytes: 166056
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <string.h>
#include <array>
#include <bitset>

using namespace std;

const int maxn=2e5+5;

int a[maxn];
int prosl[maxn];
int s[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	for(int i=0; i<n; i++){
		cin >> a[i];
		prosl[i]=a[i];
	}
	bool p;
	int val;
	for(int i=0; i<k; i++){
		for(int j=0; j<n; j++){
			s[max(0, j-a[j])]++;
			s[min(n, j+a[j]+1)]--;
		}
		val=0;
		for(int j=0; j<n; j++){
			val+=s[j];
			s[j]=0;
			a[j]=val;
		}
		p=1;
		for(int j=0; j<n; j++){
			if(prosl[j]!=a[j]){
				prosl[j]=a[j];
				p=0;
			}
		}
		if(p){
			break;
		}
	}
	for(int i=0; i<n; i++){
		cout << a[i] << " ";
	}
	cout << '\n';
	return 0;
}

Measured memory_bytes: 5936
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var x = Integer.parseInt(br.readLine());
      System.out.println(x >= 30 ? "Yes" : "No");
    }
  }
}


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

int main(){
  double a,b,c,h,m,si,pi;
  cin >> a >> b >> h >> m;
  h=h*60+m;
  pi=3.1415926535897932382644;
  si=abs(h/720-m/60);
  c=a*a+b*b-2*a*b*cos(2*si*pi);
  c=pow(c,0.5);
  printf("%0.15f",c);
}

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

using namespace std;

template<typename T = int>
vector<T> dijkstra(const vector<vector<pair<int, T>>> &G, int st, const T inf) {
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq;
    pq.push({0, st});
    vector<T> dist(G.size(), inf);
    dist[st] = 0;
    while (!pq.empty()) {
        const auto now = pq.top();
        pq.pop();
        for (auto nxt : G[now.second]) {
            const T nextCost = now.first + nxt.second;
            if (dist[nxt.first] <= nextCost) {
                continue;
            }
            dist[nxt.first] = nextCost;
            pq.push(make_pair(nextCost, nxt.first));
        }
    }
    return dist;
}

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, long long>>> Graph(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        long long c;
        cin >> a >> b >> c;
        a--;
        b--;
        Graph[a].emplace_back(make_pair(b, c));
        Graph[b].emplace_back(make_pair(a, c));
    }
    int q, k;
    cin >> q >> k;
    k--;
    vector<long long> dist = dijkstra<long long>(Graph, k, (long long) 1e18);
    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        x--;y--;
        cout << dist[x] + dist[y] << endl;
    }
}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define big 998244353
#define ff first
#define se second
#define pb push_back
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define mp make_pair
#define pi 3.141592653589
int power(int x,int y){
    int r=1,z=x;
    while(y){
        if(y & 1)r*=z;
        z*=z;y=y>>1;}
    return r;}
int powerm(int x,int y,int p){
    int r=1;
    while(y){
        if(y & 1)r=(r*x)%p;
        y=y>>1;
        x=(x*x)%p;}
    return r%p;}
int modinv(int x,int m){
    return powerm(x,m-2,m);}
int logarithm(int a,int b){
    int x=0;
    while(a>1){
        x++;
        a/=b;}
    return x;}
vector<int> a,b,c,d,v;
int n,q,m,ans;
void func(int id,int num){
    if(id==n){
        int sum=0;
        for(int i=0;i<q;i++)
            if(v[b[i]]-v[a[i]]==c[i])
                sum+=d[i];
        ans=max(ans,sum);
    return;
    }
    for(int i=num;i<=m;i++){
        v.pb(i);
        func(id+1,i);
        v.pop_back();
    }
}
int32_t main(){
    fast;
    cin>>n>>m>>q;
    ans=INT_MIN;
    for(int i=0;i<q;i++){
        int l,r,m,o;
        cin>>l>>r>>m>>o;
        a.pb(l);
        b.pb(r);
        c.pb(m);
        d.pb(o);
        a[i]--;
        b[i]--;
    }
    func(0,1);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int[] a = new int[3];
        
        for (int i=0; i<3; i++) {
            a[i] = scanner.nextInt();
            
            if (a[i] < 1 || a[i] > 13) return;
        }

        if (a[0] + a[1] + a[2] >= 22)
            System.out.println("bust");
        else System.out.println("win");
    }
}

Measured memory_bytes: 22740
//b
#include <iostream>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <functional>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>

#define REP(i,b,n) for(int i=b;i<n;i++)
#define REPR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PB push_back
#define MP make_pair

using namespace std;

static const double PI = acos(-1.0);
static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> pii;	

int main(){
	
	ll e;
	
	while(cin>>e, e){
	
		ll mn = e;
		
		for(ll y=0; e-y*y >= 0; ++y){
			for(ll z=0; e-z*z*z>=0; ++z){
				
				if( e - y*y - z*z*z >= 0){
					mn = min(mn, e - y*y - z*z*z + y + z);
				}
			}
		}
		
		cout << mn << endl;
		
	}
	
	return 0;	
}

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

int main(){
 
  int r,g,b,n;
  cin >> r >> g >> b >>n;
  int sum = 0;
  int cnt = 0;
  
  int sr = n / r; // i=4 , j=2
  int sg = n / g;
  for(int i=sr;i >= 0;--i){
      for(int j=sg;j >= 0;--j){
         sum = 0;
         sum += i*r + j*g;
         if(sum <= n && (n-sum)%b == 0){
         	cnt++;
         }
      }

  }

  cout << cnt <<endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
//プロトタイプ宣言
int gcd(int , int);
void often(void);
int get_digent(int);


int main(){
  often();
  int N, D; cin >> N >> D;
  vvi X(N, vi(D));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < D; ++j) {
      cin >> X[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i+1; j < N; ++j) {
      int norm = 0;
      for (int k = 0; k < D; ++k) {
        int diff = abs(X[i][k] - X[j][k]);
        norm += diff * diff;
      }
      bool flag = false;
      for (int k = 0; k <= norm; ++k) {
      if (k * k == norm) {
        flag = true;
      }
    }
    if (flag) ++ans;
  }
}
cout << ans << endl; 
}








































//以下、ライブラリ

int gcd(auto a, auto b) {
  return b ? gcd(b, a%b) : a;
}  //ユークリッドの互除法

void often(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int get_digent(int x){
  string s;
  s = to_string(x);
  int digent = s.size();
  return digent;
} 

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

dp = [100000000000000] * N
(dp[0], dp[1]) = [0, abs(a[1]-a[0])]

for i in range(2,N):
    dp[i] = min(dp[i], dp[i - 1] + abs(a[i - 1] - a[i]))
    dp[i] = min(dp[i], dp[i - 2] + abs(a[i - 2] - a[i]))
else:
    print(dp[N - 1])

Measured memory_bytes: 13976
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589
#define endl "\n"
#define int long long
#define ld long double
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define fr(i,a,b) for (int i = (a); i < (b); ++i)

int dp[101][100001];

void solve(){
    int n, W;
    cin >> n >> W;
    int w[n], c[n];
    //cout << 1;
    fr(i, 0, n) cin >> w[i] >> c[i];
    fr(i, 0, 1e5 + 1){
        dp[0][i] = W + 1;
    }
    dp[0][0] = 0;
    //cout << 1;
    fr(i, 0, n){
        fr(j, 0, 1e5 + 1){
            if(j < c[i]) dp[i + 1][j] = dp[i][j];
            else dp[i + 1][j] = min(dp[i][j], dp[i][j - c[i]] + w[i]);
        }
    }
    //cout << 1;
    int ans = 0;
    fr(i, 0, 1e5 + 1){
        if (dp[n][i] <= W) ans = i;
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t;
    t = 1;
    //cin >> t;
    while(t--) {solve();}
    return 0;
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int A, B;
    cin >> A >> B;
    cout << (A <= 8 && B <= 8 ? "Yay!" : ":(") << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
N,Q = map(int,input().split())
ab = [ tuple(map(int,input().split())) for i in range(N-1) ]
px = [ tuple(map(int,input().split())) for i in range(Q) ]
dic = {}
dic2=[0]*(N+1)
dic3=[0]*N

for i in range(N):
    dic[i+1] = []
for i in range(N-1):
    tmp1 = ab[i][0]
    tmp2 = ab[i][1]
    dic[tmp1].append(tmp2)
    dic[tmp2].append(tmp1)
ab=0
for i in range(Q):
    dic2[px[i][0]] += px[i][1]
px=0
def rec(now_node,prevval):
    nowval = prevval + dic2[now_node]
    dic3[now_node-1] = nowval
    tg_list = dic[now_node][:]
    for elem in tg_list:
        dic[elem].remove(now_node)
        rec(elem,nowval)
rec(1,0)
res = [str(dic3[i-1]) for i in range(1,N+1)]
print(' '.join(res))


Measured memory_bytes: 265372
import math

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


C_multiple = B // C - A // C
D_multiple = B // D - A // D 

if A % C == 0:
    C_multiple += 1
if A % D == 0:
    D_multiple += 1
        

CD_gcd = C * D // math.gcd(C,D) 
CD_multiple = B // CD_gcd - A// CD_gcd 
if A % CD_gcd == 0:
    CD_multiple += 1



ans = ( B - A + 1 ) - (C_multiple + D_multiple - CD_multiple)
print(int(ans))

Measured memory_bytes: 9188
#include <iostream>
#include <vector>


class Graph {
public:
    std::vector<int> d, v;
    std::vector<std::vector<int>> arr;
    int n;
    int tp = 1;

    Graph(int n) : n(n) {
        d = std::vector<int>(n, 0);
        v = std::vector<int>(n, 0);
        arr = std::vector<std::vector<int>>(n);
    }
    
    void depth_search(int i) {
        if (d[i] == 0) {
            d[i] = tp;
            tp++;
            for (auto j : arr[i]) {
                depth_search(j - 1);
            }
            v[i] = tp;
            tp++;
        }
    }

    void print() {
        for (int i = 0; i < n; i++) {
            std::cout << i + 1 << " " << d[i] << " " << v[i] << std::endl;
        }
    }
};


int main() {
    int n;
    std::cin >> n;

    Graph graph(n);
    
    for (int i = 0; i < n; i++) {
        int u, k;
        std::cin >> u >> k;
        std::vector<int> vs(k);
        
        for (int i = 0; i < k; i++) {
            std::cin >> vs[i];
        }
        graph.arr[u - 1] = vs;
    }

    for (int i = 0; i < n; i++) {
        graph.depth_search(i);
    }

    graph.print();

}



Measured memory_bytes: 3116
import itertools, copy
h,w,k = map(int, input().split())
c = []
for i in range(h):
    cc = list(input())
    c.append(cc)
li_h = range(h)
li_w = range(w)
count = 0
for n in range(0, len(li_h)+1):
    for conb_h in itertools.combinations(li_h, n):        
        for m in range(0, len(li_w)+1):
            for conb_w in itertools.combinations(li_w, m):
                ccc = copy.deepcopy(c)
                for i in list(conb_h):
                    for ii in range(w):
                        ccc[int(i)][ii] = '.'
                for j in list(conb_w):
                    for jj in range(h):
                        ccc[jj][int(j)] = '.'
                _count = 0
                for item in ccc:
                    _count += item.count('#')
                if _count == k:
                    count += 1
print(count)

Measured memory_bytes: 9364
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n,a,b,x;
	cin>>n>>a>>b;
	x=abs(b-a);
	if(x%2==0)
	cout<<"Alice"<<endl;
	else
	cout<<"Borys"<<endl;
	return 0;
}

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

using namespace std;

int main(){
    long long int N;
    cin >> N;
    vector<long long int> A(N),sum(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }

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

    for(int i=0;i<N;i++){
        if(i==0){
            sum[i] = A[i];
        }else{
            sum[i] = sum[i-1] + A[i];
        }
    }

    for(int i=N-1;0<=i;i--){
        if(2*sum[i-1]<A[i]){
            cout << N-i << endl;
            return 0;
        }
    }

    cout << N << endl;
}

Measured memory_bytes: 1792
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

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

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int a,b;
    cin>>a>>b;
    int ab=a*b;
    int abc=false;
    for(int i=1;i<=3;i++){
        if((ab*i)%2!=0)
            abc=true;
    }
    if(abc==true)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d", $in_k);
fscanf(STDIN, "%s", $in_s);

$ans = "";

if(strlen($in_s) > $in_k){
    $ans = substr($in_s, 0, $in_k)."...";
}else{
    $ans = $in_s;
}

echo "$ans\n";


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;


struct dsu0 {
    vector<int> par, siz;
    int n;
    int cc;
    int largest;
    void init(int n) {
	assert(n>0);
	this->n=n;
	cc=n;
	par.resize(n+10);siz.resize(n+10);
	for (int i=0; i<n; i++) par[i]=i,siz[i]=1;
	largest=1;
    }
    int parent(int x) {
	assert(x>=0 && x<n);
	return par[x]==x?x:par[x]=parent(par[x]);
    }
    bool join(int x, int y) {
	x=parent(x);y=parent(y);
	if (x==y) return false;
	cc--;
	if (siz[x]<siz[y]) swap(x,y);
	siz[x]+=siz[y];par[y]=x;
	largest=max(largest,siz[x]);
	return true;
    }
};

int n, m;

vector<pair<int,int>> edges;


bool check(int ban) {
    dsu0 dsu;
    dsu.init(n);
    for (int i=0; i<m; i++) {
	if (i==ban) continue;
	dsu.join(edges[i].first,edges[i].second);
    }
    return dsu.cc>1;
}

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

    cin>>n>>m;
    for (int i=0; i<m; i++) {
	int u,v;
	cin>>u>>v;
	--u; --v;
	edges.emplace_back(u,v);
    }


    int res = 0;

    for (int i=0; i<m; i++) {
	res += check(i);
    }

    out(res);
    
    
    return 0;
}


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

int main() {
    vector<int> a(101);
  int n,p=0,q=0;
  cin>>n;
  for (int i = 0; i < n; i++) cin >> a.at(i);
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
 for(int i=0;i<n;i++) (i % 2 == 0 ? p += a.at(i) : q += a.at(i));
	cout << p-q << endl; 
}

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

//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
typedef long long ll;
const ll mod = 10000000000;

ll h, w;
ll ans;

ll max3(ll a, ll b, ll c) {
	return max(a, max(b, c));
}

ll min3(ll a, ll b, ll c) {
	return min(a, min(b, c));
}

void solve() {
	ll a, b, c, now;
	rep(i, 1, h) {
		a = i*w;
		b = (h - i)*floor(w / 2.0);
		c = (h - i)*ceil(w / 2.0);
		now = max3(a, b, c) - min3(a, b, c);
		ans = min(ans, now);
		b = w*floor((h - i) / 2.0);
		c = w*ceil((h - i) / 2.0);
		now = max3(a, b, c) - min3(a, b, c);
		ans = min(ans, now);
	}
}

int main() {
	cin >> h >> w;
	if (h % 3 == 0 || w % 3 == 0) { print(0); return 0; }
	ans = h*w;
	solve();
	swap(h, w);
	solve();
	print(ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int i = 1;
		int x = 0;
		while(sc.hasNextInt()){
			x = sc.nextInt();
			if(x == 0)break;
			System.out.println("Case "+i+": "+x);
			i++;
		}
	}
	}

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

int main()
{
	vector<string> dat;
	int n;
	cin >> n;
	for (size_t i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		dat.push_back(s);
	}
	for (size_t i = 1; i < n; i++)
	{
		if (*(dat.at(i - 1).end() - 1) != dat.at(i).at(0))
		{
			cout << "No" << endl;
			return 0;
		}
		for (size_t j = 0; j < i; j++)
		{
			if (dat.at(i) == dat.at(j))
			{
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.length()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>())
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////
	string s;
	cin >> s;
	bool l = false;
	SREP(i,s){
		if(s[i]=='9') l=true;
	}
	if(l==true) cout << "Yes" << endl;
	else cout << "No" << endl;
//////////////////////////////////////////////
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;

int n;
int a[N], b[N], c[N];
long long d[N], v[N];

void deal(int a[], int b[])
{
    for(int i = 0; i < n; ++i)
    {
        int pos = lower_bound(a, a + n, b[i]) - a;
        if(pos > 0) v[i] = d[pos - 1];
        else v[i] = 0;
    }
    d[0] = v[0];
    for(int i = 1; i < n; ++i)
        d[i] = d[i - 1] + v[i];
}

int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    sort(a, a + n);
    for(int i = 0; i < n; ++i)
        scanf("%d", &b[i]);
    sort(b, b + n);
    for(int i = 0; i < n; ++i)
        scanf("%d", &c[i]);
    sort(c, c + n);
    for(int i = 0; i < n; ++i)
        d[i] = i + 1;
    deal(a, b);
    deal(b, c);
    printf("%lld\n", d[n - 1]);
    return 0;
}


Measured memory_bytes: 2944
import Control.Applicative
import Text.Printf

stddev :: Floating a => [a] -> a
stddev ss = sqrt $ (sum [(s - m) ^ 2 | s <- ss]) / n
    where
        n = (fromIntegral . length) ss
        m = (sum ss) / n

main :: IO ()
main = do
    n <- getLine
    if (n == "0")
    then return ()
    else do
       printf "%.8f\n" =<< (stddev . map (read :: String -> Double) . words) <$> getLine
       main

Measured memory_bytes: 4980
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    int c = b - a;
    
    System.out.println(c * (c + 1) / 2 - b);
    

  }
}

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

int main()
{
  int n, m;
  vector<int> h;
  cin >> n >> m;
  vector<bool> rr(n, false);
  for (int i = 0; i < n; i++)
  {
    int t;
    cin >> t;
    h.push_back(t);
  }
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h[a] == h[b])
    {
      rr[a] = true;
      rr[b] = true;
    }
    else if (h[a] < h[b])
    {
      rr[a] = true;
    }
    else
    {
      rr[b] = true;
    }
  }

  int r = 0;
  for (int i = 0; i < n; i++)
  {
    if (rr[i] == false)
    {
      r++;
    }
  }
  cout << r << endl;
}


Measured memory_bytes: 3944
#1,2,3,4,5,6,7,8,9
#10,11,12,21,22,23,32,33,34,43,44,45,54,55,56,....,98,99
#100,101,110,111,112,121,122,123
#210,211,212,221,222,223,232,233,234
#321,322,323,332,333,334,343,344,345
#1000,1001,1010,1011,1012,

from collections import deque

def main():
    K=int(input())

    lnln=deque([i for i in range(1,10)])

    for _ in range(K):
        n=lnln.popleft()
        if n%10!=0:
            lnln.append(n*10+(n%10)-1)
        lnln.append(n*10+(n%10))
        if n%10!=9:
            lnln.append(n*10+(n%10)+1)

    print(n)

if __name__=="__main__":
    main()


Measured memory_bytes: 68420
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
int n;
int main() {
//	freopen("1.txt","r",stdin);
	read(n);
	printf("%d\n",n*n);
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 1005;

vector<int> G[MAX_N];
vector<int> gx[MAX_N],gy[MAX_N];
bool visit[MAX_N][MAX_N];
bool ok[200001];
bool okk[200001];
bool x[MAX_N][MAX_N],y[MAX_N][MAX_N];
int id[MAX_N][MAX_N];

void dfs(const int st,int u,bool hoge[MAX_N][MAX_N],vector<int>* g)
{
	hoge[st][u] = true;
	each(v,g[u]){
		if(!hoge[st][v]){
			dfs(st,v,hoge,g);
		}
	}
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin >> n >> m;
	rep(i,m){
		int a,b;
		cin >> a >> b;
		--a,--b;
		G[a].pb(b);
		id[a][b] = i;
	}
	rep(i,n){
		dfs(i,i,visit,G);
	}
	rep(i,n){
		x[i][i] = y[i][i] = true;
		rep(j,n){
			gx[j].clear(),gy[j].clear();
			if(i == j) continue;
			rep(k,len(G[j])){
				gx[j].pb(G[j][k]);
				gy[j].pb(G[j][k]);
			}
		}
		rep(j,len(G[i])){
			okk[id[i][G[i][j]]] = visit[G[i][j]][i];
			ok[id[i][G[i][j]]] |= x[i][G[i][j]];
			gx[i].pb(G[i][j]);
			dfs(i,G[i][j],x,gx);
		}
		rrep(j,len(G[i])){
			ok[id[i][G[i][j]]] |= y[i][G[i][j]];
			gy[i].pb(G[i][j]);
			dfs(i,G[i][j],y,gy);
		}
	}
	rep(i,m){
		if(ok[i] == okk[i]){
			cout << "same\n";
		}else{
			cout << "diff\n";
		}
	}
	return 0;
}

Measured memory_bytes: 12800
N = int(input())
A = list(map(int, input().split()))

L = [A[i] + (i + 1) for i in range(N)]
R = [(i + 1) - A[i] for i in range(N)]
import collections
dL = dict(collections.Counter(L))
dR = dict(collections.Counter(R))

ans = 0
for k in dL.keys():
    ans += dL[k] * dR.get(k, 0)
print(ans)
# print(L)
# print(R)

Measured memory_bytes: 192700
#include<cstdio>
#include<algorithm>
using namespace std;

typedef long long ll;
const int MAXN=2e6+5;
const int MOD=1e9+7;

int x3,y3,x4,y4;
ll fac[MAXN],finv[MAXN];

void Init(){
    fac[0]=1;
    for(int i=1;i<MAXN;i++) fac[i]=fac[i-1]*i%MOD;
    finv[1]=1;
    for(int i=2;i<MAXN;i++) finv[i]=(MOD-MOD/i)*finv[MOD%i]%MOD;
    finv[0]=1;
    for(int i=1;i<MAXN;i++) finv[i]=finv[i]*finv[i-1]%MOD;
}

ll F(int x1,int y1,int x2,int y2){return 1ll*(fac[x2-x1+y2-y1]*finv[x2-x1]%MOD)*finv[y2-y1]%MOD;}

struct node{
    int x,y,k;
}a[4],b[4];

ll sol(node p,node q){
    int x1=p.x,y1=p.y,x2=q.x,y2=q.y;
    ll res=0;
    for(int i=x3;i<=x4;i++) res=(1ll*res+1ll*(F(x1,y1,i,y3-1)*F(i,y3,x2,y2)%MOD)*(-i-y3)%MOD)%MOD;
    for(int j=y3;j<=y4;j++) res=(1ll*res+1ll*(F(x1,y1,x3-1,j)*F(x3,j,x2,y2)%MOD)*(-j-x3)%MOD)%MOD;
    for(int i=x3;i<=x4;i++) res=(1ll*res+1ll*(F(x1,y1,i,y4)*F(i,y4+1,x2,y2)%MOD)*(i+y4+1)%MOD)%MOD;
    for(int j=y3;j<=y4;j++) res=(1ll*res+1ll*(F(x1,y1,x4,j)*F(x4+1,j,x2,y2)%MOD)*(j+x4+1)%MOD)%MOD;
    return res;
}

int main(){
    Init();
    int x1,x2,x5,x6;
    int y1,y2,y5,y6;
    scanf("%d%d%d%d%d%d",&x1,&x2,&x3,&x4,&x5,&x6);
    scanf("%d%d%d%d%d%d",&y1,&y2,&y3,&y4,&y5,&y6);
    a[0]=(node){x2,y2,1},a[1]=(node){x2,y1-1,-1},a[2]=(node){x1-1,y2,-1},a[3]=(node){x1-1,y1-1,1};
    b[0]=(node){x6+1,y6+1,1},b[1]=(node){x6+1,y5,-1},b[2]=(node){x5,y6+1,-1},b[3]=(node){x5,y5,1};
    ll ans=0;
    for(int i=0;i<4;i++)
        for(int j=0;j<4;j++)
            ans=(1ll*ans+1ll*(a[i].k*b[j].k)*sol(a[i],b[j])%MOD)%MOD;
    printf("%lld\n",(ans+MOD)%MOD);
}


Measured memory_bytes: 31360
N = int(input())
s = (N + 1) * N / 2 if N % 2 != 0 else (N - 1) * N / 2 + N

for M,K in zip([N // 3, N // 5],[3,5]):
    s -= K*(M + 1) * M/ 2 if M % 2 != 0 else K*(M - 1) * M / 2 + K*M

M = N // 15
s += 15*(M + 1) * M / 2 if M % 2 != 0 else 15*(M - 1) * M / 2 + 15*M

print(int(s))

Measured memory_bytes: 9204
#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 a[5];
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    rep(i, 5) {
        if(a[i] == 0) {
            printf("%d\n", i + 1);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3804
#include<iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <algorithm>

using namespace std;
int main()
{
	long long i, j, N, m, a, r, c, h, tmp;
	m = 0;
	a = 0;
	r = 0;
	c = 0;
	h = 0;

	char Name[11];

	cin >> N;


	for (i = 0; i < N; i++) {
		cin >> Name;

		if (Name[0] == 77)m++;
		if (Name[0] == 65)a++;
		if (Name[0] == 82)r++;
		if (Name[0] == 67)c++;
		if (Name[0] == 72)h++;

	}

	tmp = 0;

	tmp = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;
    cout << tmp;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>

#define Rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())

#define eb emplace_back
#define ef emplace_front
#define dbg(x) cout<<#x" = "<<((x))<<endl
#define fs first
#define sc second
     
using namespace std;
     
     
typedef long long ll;
typedef pair<ll, ll> P;
     
     
int main(){
  string S, T;

  cin >> S >> T;

#ifdef DEBUG
#endif

  vector<int> start(26, -1);
  vector<int> goal(26, -1);

  for(size_t i = 0; i < S.length(); ++i){
    int a = S[i] - 'a';
    int b = T[i] - 'a';
    if(start[a] != -1 || goal[b] != -1){
      if(start[a] != b || goal[b] != a){
	cout << "No" << endl;
	return 0;
      } 
    }

    start[a] = b;
    goal[b] = a;
  } //i 

  cout << "Yes" << endl;
  
  return 0;
}


Measured memory_bytes: 776