akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; 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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll number;
    cin >> number;

    if (number < 1200) {
        cout << "ABC" << endl;
        return 0;
    } else if (number < 2800) {
        cout << "ARC" << endl;
        return 0;
    } else {
        cout << "AGC" << endl;
        return 0;
    }
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
#define rep(i,n) for (int i=0;i<n;i++)
//#include <bits/stdc++.h>
using namespace std;
const int D=365;

int main(){
    int d;
    cin>>d;
    vector<long int> c(26);
    rep(i,26) cin>>c[i];
    vector<vector<long int> > s(D,vector<long int>(26));
    rep(i,D){
        rep(j,26) cin>>s[i][j];
    }

    vector<int> last(26,-1);
    vector<long long> ans(D+1);
    vector<int> t(D);
    long long a=0;
    int n=0;
    for (int k=0;k<26;k++){
        for (int l=0;l<D;l++){
            t[l]=(l+k)%26;
        }
        for(int i=0;i<D;i++){
            ans[i+1]=ans[i]+s[i][t[i]];
            rep(j,26){
                if (t[i]==j) last[j]=i; 
                ans[i+1]-=c[j]*(i-last[j]);
            }
        }
        if (ans[D]>a){
            a=ans[D];
            n=k;
        }
    }
    //for (int i=1;i<D+1;i++)  cout<<ans[i]<<endl;
   
    rep(i,D){
        cout<<(i+n)%26+1<<endl;
    }
    return 0;
}

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


const int n_day[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
 
struct Date {
  // year, month, day, a day of the week
  int y, m, d, e;
  Date() {}
  Date(int y, int m, int d, int e = -1) : y(y), m(m), d(d), e(e) {}
 
  bool operator < (const Date &o) const {
    if(y != o.y) return y < o.y;
    if(m != o.m) return m < o.m;
    return d < o.d;
  }
 
  bool isLeapYear() {
    if(y % 400 == 0) return true;
    if(y % 100 == 0) return false;
    if(y % 4 == 0) return true;
    return false;
  }

  int getDays() {
    int nd = n_day[m];
    if(m == 2) nd += isLeapYear();
    return nd;
  }

  void next() {
    e = (e+1)%7;
    if(d == getDays()) {
      d = 1;
      if(m == 12) {
        m = 1;
        ++y;
      } else {
        ++m;
      }
    } else {
      ++d;
    }
  }
 
  void back() {
    e = (e+6)%7;
    if(d == 1) {
      if(m == 1) {
        m = 12;
        --y;
      } else {
        --m;
      }
      d = getDays();
    } else {
      --d;
    }
  }
};

// AOJ 0125
int main() {
  int y1, m1, d1, y2, m2, d2;
  while(cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2) {
    if(y1 < 0 || m1 < 0 || d1 < 0 || y2 < 0 || m2 < 0 || d2 < 0)
      break;
    Date d(y1,m1,d1), end(y2,m2,d2);
    int res = 0;
    while(d < end) {
      ++res;
      end.back();
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <bitset>
using namespace std;
constexpr int kN = 1048576;
int main() {
	int n, x;
	bitset<kN> b;
	scanf("%d", &n);
	b.reset();
	b[0] = true;
	for (int i = 100; i <= 105; i++) 
		for (long long int j = i; j < kN; j <<= 1) {
			b |= b << j;
		}
	if (b[n]) printf("1\n");
	else printf("0\n");
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, c, d, t = 0, m = 0;
    cin >> a >> b >> c >> d;
    while(a > 0)
    {
        a = a - d;
        t+=1;
    }
    while(c > 0)
    {
        c = c - b;
        m+=1;
    }
    if(t >= m)
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 3672
program bm
    implicit none
    integer::N,A(3,3),B
    logical::BINGO(3,3)=.false.,check=.false.
    integer::i,j,k
    do i=1,3
        read*,A(:,i)
    end do
    read*,N
    do i=1,N
        read*,b
        do j=1,3
            do k=1,3
                if(A(j,k)==b)BINGO(j,k)=.true.
            end do
        end do
    end do
    do i=1,3
        check=check.or.(Bingo(1,i).and.Bingo(2,i).and.bingo(3,i))
        check=check.or.(Bingo(i,1).and.Bingo(i,2).and.bingo(i,3))
    end do
    check=check.or.(Bingo(1,1).and.Bingo(2,2).and.bingo(3,3))
    check=check.or.(Bingo(1,3).and.Bingo(2,2).and.bingo(3,1))
    print"(A)",trim(merge("Yes","No ",check))
end program bm

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 +c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
        out(x / 10);
    }
    putchar('0' + x % 10);
}
struct node {
    int to,next;
}E[MAXN * 2];
int head[MAXN],sumE;
int N,M;
int cnt[MAXN];
bool vis[MAXN];
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void dfs(int u) {
    vis[u] = 1;
    for(int i = head[u] ; i ; i = E[i].next) {
        int v = E[i].to;
        if(!vis[v]) dfs(v);
    }
}
void Solve() {
    read(N);read(M);
    int a,b;
    for(int i = 1 ; i <= M ; ++i) {
        read(a);read(b);
        cnt[a]++;cnt[b]++;
        add(a,b);add(b,a);
    }
    for(int i = 1 ; i <= N ; ++i) {
        if(cnt[i] & 1) {puts("No");return;}
    }
    int t = 0;
    int p = 0,q = 0;
    for(int i = 1 ; i <= N ; ++i) {
        if(cnt[i] >= 6) {puts("Yes");return;}
        if(cnt[i] >= 4) {
            ++t;
            if(!p) p = i;
            else if(!q) q = i;
        }
    }
    if(t > 2) {puts("Yes");return;}
    if(t == 2) {
        vis[p] = 1;
        dfs(q);
        for(int i = 1 ; i <= N ; ++i) {
            if(!vis[i]) {puts("Yes");return;}
        }
    }
    puts("No");
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 3072
N, Y = map(int, input().split())
for x in range(N+1):
    for y in range(N-x+1):
        z = N-x-y
        if 0 <= z <= 2000 and 10000*x+5000*y+1000*z == Y:
            print(x, y, z)
            exit()
print(-1, -1, -1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;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 ll long long
#define INF 999999999
using namespace std;


int A[50], B[50], C[50], D[50];
int X[10];
  int S = -1;
  int N,M,Q;
void dfs(int dep,int x) {
  if (dep == N) {
    int res = 0;
    for (int i = 0; i < Q; i++) {
      if (X[B[i]] - X[A[i]] == C[i]) {
        res += D[i];
      }
    }
          S = max(res,S);
          return;
  }
  for (int i = x; i <= M; i++) {
      X[dep] = i;
      dfs(dep+1,i);
    }
}
int main() {
  cin >> N >> M >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> A[i] >> B[i] >> C[i] >> D[i];
    A[i]--;
    B[i]--;
  }
  dfs(0,1);
  std::cout << S << '\n';
}


Measured memory_bytes: 3640
ps = gets.to_i.times.map { Complex(*gets.split.map(&:to_i)) }
i, r = 0, 0
while ps.size >= 3
  u, v = ps[(i+1)%ps.size] - ps[i], ps[i-1] - ps[i]
  a = (v / u).arg
  if a > 0
    c = (u.conj * v).imag
    x = Complex(*v.rect.reverse!)
    y = -Complex(*u.rect.reverse!)
    if ps.size.times.reject {|j| j == i || j == (i-1)%ps.size || j == (i+1)%ps.size }.all? {|j|
         w = ps[j] - ps[i]
         s = (x * w).real.to_f / c
         t = (y * w).real.to_f / c
         !(s >= 0 && t >= 0 && s + t <= 1)
       }
      r += c * 0.5
      ps.delete_at i
      i %= ps.size
    else
      i = (i+1)%ps.size
    end
  else
    i = (i+1)%ps.size
  end
end
puts '%.1f' % r

Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int INF = 0x3f3f3f3f;
int main() {
  string a, b;
  cin >> a >> b;
  cout << b + a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[100005] = {}, b[100005] = {}, c[100005] = {};
    ll d[100005] = {}, z = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    for (int i = 1; i <= n; i++) cin >> c[i];
    sort(a + 1, a + n + 1); sort(b + 1, b + n + 1); sort(c + 1, c + n + 1);
    for (int i = 1; i <= n; i++) d[i] = d[i - 1] + (int)(lower_bound(a + 1, a + n + 1, b[i]) - a - 1);
    for (int i = 1; i <= n; i++) z += d[(int)(lower_bound(b + 1, b + n + 1, c[i]) - b - 1)];
    cout << z;
}


Measured memory_bytes: 2176
n = gets.chomp("").to_i

h = gets.split(" ").map(&:to_i)

max = h[0]

if n != 1
  (n-1).times do |i|
    if max-1 > h[i+1]
      puts "No"
      break
    else
      if max < h[i+1]
        max = h[i+1]
      end
    end

    if n-2 == i
      puts "Yes"
    end
  end
else
  puts "Yes"
end


Measured memory_bytes: 8580
#include <iostream>

using namespace std;

int main() {
  int N, T;
  cin >> N >> T;
  
  int lowestCost = 0;
  for (int n = 0; n < N; n++) {
	int c, t;
	cin >> c >> t;
	if (t > T) {
	  continue;
	}

	if (c < lowestCost || lowestCost == 0) {
	  lowestCost = c;
	}
  }
  if (lowestCost > 0)
	cout << lowestCost << endl;
  else
	cout << "TLE" << endl;


  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int A=0;
  int B =1000000000;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
      for (int j = 0; j < 1000000000; j++) {
        if (x%2==0){
          A++;
          x /= 2;
        }
        else
          break;
      }

    if (A<B){
      B=A;
    }

        A=0;
    
  }
  cout << B <<endl;
}

Measured memory_bytes: 256
import math

N=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))

dig=[1]*(N+1)
dig[0]=0
a=1
for i,pp in enumerate(p):
    a+=sum(dig[:pp])*math.factorial(N-i-1)
    dig[pp]=0

dig=[1]*(N+1)
dig[0]=0
b=1
for i,qq in enumerate(q):
    b+=sum(dig[:qq])*math.factorial(N-i-1)
    dig[qq]=0
print(abs(a-b))


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <complex>
#include <cstring>
#include <cmath>
#include <string>
using namespace std;
#define min(a,b) a<b?a:b;
#define max(a,b) a>b?a:b;
#define LL long long
const int N = 210;
const double eps = 1e-8;
double dp[N][N],p[N][N],ans[N];//莠コ?御シ第?蜃?惻縲よ慮髣エ?梧ヲら紫
double zu[N][N];
int n;
struct node{
	double p,t,v;
}data[N];
void zuhe()
{
	memset(zu,0,sizeof(zu));
	int i,j;
	for(i=0;i<=50;i++)
	{
		zu[i][0]=1;
		zu[i][1]=i;
	}
	for(i=2;i<=50;i++)
		for(j=1;j<=i;j++)
			zu[i][j]=zu[i-1][j]+zu[i-1][j-1];
}
int main()
{
	int i,j,z,k,m,l;
	double sum,res,time1,time2;
	zuhe();
	while(scanf("%d%d%d",&n,&m,&l)!=EOF)
	{
		for(i=1;i<=n;i++)
			scanf("%lf%lf%lf",&data[i].p,&data[i].t,&data[i].v);
		for(i=1;i<=n;i++)
			for(j=0;j<=m;j++)
				p[i][j]=zu[m][j]*pow(data[i].p/100.0,j*1.0)*pow((1-data[i].p/100.0),(m-j)*1.0);
		for(i=1;i<=n;i++)
		{
			ans[i]=0;
			for(j=0;j<=m;j++)
			{
				res=p[i][j];
				time1=j*data[i].t+l/data[i].v;
				for(z=1;z<=n;z++)
				{
					sum=0;
					if(z==i)
						continue;
					for(k=0;k<=m;k++)
					{
						time2=k*data[z].t+l/data[z].v;
						if(time1<time2-eps)
							sum+=p[z][k];
					}
					res*=sum;
				}
				ans[i]+=res;
			}
		}
		for(i=1;i<=n;i++)
			printf("%.8lf\n",ans[i]);
	}
	return 0;
}



/*
2 2 50
30 50 1
30 50 2

2 1 100
100 100 10
0 100 1

3 1 100
50 1 1
50 1 1
50 1 1

2 2 50
30 0 1
30 50 2

  */

Measured memory_bytes: 1420
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,d,a=0;cin>>m>>d;
  if(d==1||m<4)cout<<0<<endl;
  else{
    for(int i=1;i<=m;i++){
      for(int j=2;j<=d;j++){
        int k=j%10,l=j/10;
        if(k*l==i&&k!=1&&l!=1)a++;
      }
    }
    cout<<a<<endl;
  }
}
        
      


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define REPA(x, v) for(auto&& x:v)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(v.rbegin(),v.rend())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;
    REP(i, n){
        ans += s[i]-'0';
    }
    Yes(!(ans%9));
}

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

using namespace std;
int main()

{
    string n;
  cin >> n;

    for (int i = 0; i < 3; i++) {

        if (n[i] == '1') {
            n[i] = '9';
        } else if (n[i] == '9') {
            n[i] = '1';
        }
    }

    cout << n << endl;


  return 0;
}

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

typedef long long ll;

int n , m;

int a[30][30];
vector<int> cnt(30);
int k[30];

int main(){
    cin >> n >> m;
    cnt.resize(m+1);
    for (int i = 0; i < n; i++){
        cin >> k[i];
        for (int j = 0; j < k[i]; j++){
            cin >> a[i][j] ;
            cnt[a[i][j]]++;
        }
    }

    int res = 0;
    for (int i = 1; i <= m; i++){
        if (cnt[i] == n){
            res++;
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include <stdlib.h>
#include <string.h>



int main()
{

    int  N;
    int  N0, N1,N2,N3;
   int f0=0,f1=0,f2=0;
    
 // 整数の入力
    scanf("%d", &N);
     N0 = N % 10;
     N1 = (N/10 % 10);
     N2 = (N/100)% 10;
     N3 = N/1000;

   if (N0==N1){
     f0=1;
}
   if(N1==N2){
     f1=1 ;
  }
   if(N2==N3){
     f2=1 ;
  }

//     printf("%d %d %d %d %d %d %d\n",N0,N1,N2,N3,f1,f2,f2);
   if ((f0&f1)||(f1&f2)){
     printf("Yes\n");
  }else {
printf("No\n");
}
    return 0;
}


Measured memory_bytes: 128
K, N = map(int, input().split())
l = list(map(int, input().split()))

l_ans = []

for i in range(N):
    if i + N - 1 < N:
        l_ans.append(l[i + N - 1] - l[i])
    else:
        l_ans.append(K - l[i] + l[i - 1])

print(min(l_ans))


Measured memory_bytes: 26480
import java.util.Scanner;

public class Main{
	static int keta(int s) {
		int sum = 0;
		while(s > 0) {
			sum += (s % 10);
			s /= 10;
		}
		return sum;
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), A = sc.nextInt(), B = sc.nextInt();
		int[] keta = new int[N + 1];
		for(int i = 0; i < N + 1; i++) keta[i] = keta(i);
		int sum = 0;
		for(int i = 1; i < N + 1; i++) {
			if(keta[i] >= A && keta[i] <= B) sum += i;
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 21844
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	xx := make([]int, n)
	org := make([]int, n)
	for i := 0; i < n; i++ {
		org[i] = getNextInt(scanner)
		xx[i] = org[i]
	}

	sort.Ints(xx)

	for i := 0; i < n; i++ {
		if org[i] >= xx[n>>1] {
			fmt.Fprintln(writer, xx[(n>>1)-1])
			continue
		}
		fmt.Fprintln(writer, xx[(n>>1)])
	}

	writer.Flush()
}


Measured memory_bytes: 9856
import java.util.*;
import java.io.*;

public class Main {
  
  public static void main(String[] args) {
    // System.out.println(new Pair(2, 3).compareTo(new Pair(3, 2)));
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    // FastReader in = new FastReader();
    PrintWriter out = new PrintWriter(System.out);

    int n = in.nextInt();
    int W = in.nextInt();

    int[] w = new int[n];
    int[] v = new int[n];

    int V = 0;
    for (int i = 0; i < n; i++) {
      w[i] = in.nextInt();
      v[i] = in.nextInt();
      V += v[i];
    }

    long[] dp = new long[V + 1]; 
    // dp[i]: min W to achieve value of i

    long INF = (long) 1e12 + 7;

    Arrays.fill(dp, INF);
    dp[0] = 0;

    for (int i = 0; i < n; i++) {
      for (int j = V; j >= v[i]; j--) {
        dp[j] = Math.min(dp[j], dp[j - v[i]] + w[i]);
      }
    }

    for (int i = V; i >= 0; i--) {
      if (dp[i] <= W) {out.println(i);out.flush();return;}
    }

    out.println(0);

    
    out.flush();

  }

  static int[] knapsack(Item item, int C) {
    C = C - item.price;
    int[] dp = new int[C + 1];
    Arrays.fill(dp, item.price * item.value);
    int n = item.subs.size();

    for (int i = 0; i < n; i++) {
      for (int j = C; j >= item.subs.get(i).price; j--) {
        dp[j] = Math.max(dp[j], dp[j - item.subs.get(i).price] + item.subs.get(i).price * item.subs.get(i).value);
      }
    }
    return dp;
  }

  static class Item {
    int price, value;
    List<Item> subs;
    Item(int p, int v) {price = p; value = v; subs = new ArrayList<>();}
    int getTotal() {
      int tt = price;
      for (Item i : subs) {tt += i.price;}
      return tt;
    }
  }

  
  static class FastReader {

    public BufferedReader br; 
    StringTokenizer st; 

    public FastReader() {br = new BufferedReader(new InputStreamReader(System.in));} 

    String next() { 
      while (st == null || !st.hasMoreElements()) { 
          try {st = new StringTokenizer(br.readLine());} 
          catch (IOException e) {e.printStackTrace();} 
      } 
      return st.nextToken(); 
    } 

    int nextInt() {return Integer.parseInt(next());} 

    long nextLong() {return Long.parseLong(next());} 

    double nextDouble() {return Double.parseDouble(next());} 

    String nextLine() {
      String str = ""; 
        try {str = br.readLine();} 
        catch (IOException e) {e.printStackTrace();} 
        return str; 
  }
}

} 

  



  
  


  















Measured memory_bytes: 24148
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int x,y;
int fie[20][20];
long long int dp[20][20];
long long int ans=0;

int main(void){
	while(1){
		scanf("%d%d",&x,&y);
		if(x==0 && y==0)break;
		memset(fie,0,sizeof(fie));
		memset(dp,0,sizeof(dp));
		ans=0;

		for(int i=0;i<y;i++){
			for(int j=0;j<x;j++){
				scanf("%d",&fie[j][i]);
			}
		}
		for(int i=0;i<x;i++){
			if(fie[i][0]==0)dp[i][0]=1;
			if(fie[i][0]==2)dp[i][2]=1;
		}
		for(int i=0;i<y;i++){
			for(int j=0;j<x;j++){
				if(fie[j][i]==0){
					for(int k=j-1;k<=j+1;k++){
						if(k>=0 && k<x){
							if(fie[k][i+1]==0){
								dp[k][i+1]+=dp[j][i];
							}
							if(fie[k][i+1]==2 && k==j){
								dp[k][i+1]+=dp[j][i];
							}
						}
					}
				}
				if(fie[j][i]==2){
					dp[j][i+2]+=dp[j][i];
				}
			}
		}
		for(int i=0;i<y;i++){
				for(int j=0;j<x;j++){
					if(i>=y-2 && fie[j][i]==2)ans+=dp[j][i];
					if(i==y-1 && fie[j][i]==0)ans+=dp[j][i];
			}
		}
		printf("%lld\n",ans);
	}
    return 0;
}

Measured memory_bytes: 1192
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


# --------------------------------------------

dp = None


def main():
    n, m = li_input()
    print((n - 1) * (m - 1))


main()


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

#define ALL(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  int a, b ;
  cin >> a >> b ;
  
  if(a<=8 && b<=8){
    cout <<"Yay!"<<endl ;
  }
  else{
    cout <<":("<<endl ;
  }
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int a=5,b=14,c=80,k=0;
  scanf("%d %d %d",&a,&b,&c);
  for ( ; a <= b; a++){
    if(c % a == 0){
    k++;
    }
  }

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



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

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b==c||b+c==a||a+c==b){
        cout<<"Yes"<<endl;
    
    }
    else{
        cout<<"No"<<endl;
    
    }
    return 0;
}


Measured memory_bytes: 256
//InTheNameOfGod
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,j,k) for(int i=j;i<k;++i)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define pb push_back
#define lb(i) i&(-i);
const int maxn = 1;
string s;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>s;
    s[3]='8';
    cout<<s;
    return 0;
}


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

int main(){
  int H,W;
  cin >> H >> W;
  vector<bool> tate(H),yoko(W);
  vector<vector<char>> A(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> A.at(i).at(j);
      if(A.at(i).at(j)=='#'){
        tate.at(i)=true;
        yoko.at(j)=true;
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(tate.at(i) && yoko.at(j)){
        cout << A.at(i).at(j);
      }
      if(j==W-1 && tate.at(i)){
        cout << endl;
      }
    }
  }
} 

Measured memory_bytes: 3644
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    int N;

    cin >> N;

    vector<int> monster(N + 1);

    long long int count = 0;

    for(int i = 0; i < N + 1; i++) {
        cin >> monster[i];
    }

    long long int city_front = monster[0];

    for(int i = 1; i < N + 1; i++) {
        long long int city_back = monster[i];

        int hero;
        cin >> hero;

        if(city_front >= hero) {
            count += hero;
        } else {
            count += city_front;
            hero -= city_front;
            if(city_back >= hero) {
                count += hero;
                city_back -= hero;
            } else {
                count += city_back;
                city_back = 0; 
            }
        }

        city_front = city_back;
    }

    cout << count << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n, int r) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}

int n,a,b,cnt=0;
vi g[M];
int flag[M];
int dist1[M]={},distn[M]={};
void __dist(int node,int y[]){
	flag[node]=true;
	for(auto x:g[node])
		if(!flag[x]){
			y[x]=(y[node]+1);
			__dist(x,y);
		}
}

int main(){
	cin>>n;
	rep(i,0,n-1){
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	rep(i,0,n+1)flag[i]=false;
	__dist(1,dist1);
	rep(i,0,n+1)flag[i]=false;
	__dist(n,distn);
	int X=0,Y=0;
	rep(i,1,n+1){
		if(dist1[i]<=distn[i])X++;
		else Y++;
	}

	if(X>Y)print("Fennec");
	else print("Snuke");


}

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

#define FOR(i, a, b) for (int i=(a); i<(b); ++i)
#define ROF(i, a, b) for (int i=(a); i>(b); --i)
#define lg long long

template <class T> ostream& operator<<(ostream& os, vector<T>& x) {
    os << '[';
    bool first = true;
    for (T i : x) {
        if (!first) os << ", ";
        first = false;
        os << i;
    }
    return os << ']';
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int R, C, RR, CC;
    cin >> R >> C >> RR >> CC;

    if (R%RR == 0 && C%CC == 0) {
        cout << "No" << '\n';
        exit(0);
    }

    cout << "Yes" << '\n';

    bool swapped = false;
    if (C%CC == 0) {
        swapped = true;
        swap(R, C);
        swap(RR, CC);
    }

    vector<vector<int>> grid(R, vector<int>(C));
    
    int x = C/CC + 1;
    FOR(r, 0, R) FOR(c, 0, C) {
        if (c%CC == 0) grid[r][c] = x;
        else if ((c+1)%CC == 0) grid[r][c] = -x-1;
    }
    
    if (swapped) {
        FOR(c, 0, C) {
            FOR(r, 0, R) cout << grid[r][c] << ' ';
            cout << '\n';
        }
    } else {
        FOR(r, 0, R) {
            FOR(c, 0, C) cout << grid[r][c] << ' ';
            cout << '\n';
        }
    }
}


Measured memory_bytes: 4308
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main(){
	int k;
	cin>>k;
	string str;
	cin>>str;
	int t=str.length();
	if(k>t||k==t){
		cout<<str<<endl;
	}
	else if(k<t){
		string str1=str.substr(0,k);
		cout<<str1<<"...";
	}
	return 0;
}

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

int main(){
	string s;
	long long k;
	cin>>s>>k;

	long long length = s.length();

	char ans='1';
	for(long long i=0; i<min(length,k); i++){
		if(s[i]>='2'){
			ans=s[i];
			break;
		}
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

ll ans = 1;

int main() {
	ll N;
	rd(N);
	while (1) {
		if (ans > N) break;
		ans *= 2;
	}
	wrln(ans / 2);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>


int main() {
	int n, x, y; std::cin >> n >> x >> y;
	std::vector<int> ans(n);
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			int d = std::min({
				j - i,
				abs(x - i) + abs(j - y) + 1
			});
			ans[d]++;
		}
	}
	for (int i = 1; i < n; i++) {
		std::cout << ans[i] << std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from math import ceil
def resolve():
    n=int(input())
    CSF=[tuple(map(int,input().split())) for _ in range(n-1)]
    for i in range(n-1):
        now=0
        for j in range(i,n-1):
            c,s,f=CSF[j]
            now=f*ceil(max(s,now)/f)+c
        print(now)
    print(0)
resolve()

Measured memory_bytes: 41948
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    ans += ((n / 500) * 1000 + ((n % 500) / 5) * 5);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define SZ 100001

int N;
int arr[SZ], X;

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

	cin >> N >> X;
	for (int i = 0; i < N; ++i) cin >> arr[i];
	int minD = 1e9;
	for (int i = 0; i < N; ++i) {
		minD = min(minD, abs(X - arr[i]));
	}

	int tmp = 1;
	for (int i = 1; i*i <= minD; ++i) {
		if (minD%i == 0) {
			bool ok = true, ok2 = true;
			for (int j = 0; j < N; ++j) {
				if (abs(X - arr[j]) % (minD / i) != 0) {
					ok = false;
				}if (abs(X - arr[j]) % i != 0) {
					ok2 = false;
				}
				if (!ok && !ok2) break;
			}
			if (ok) {
				cout << minD / i; return 0;
			}
			if (ok2) {
				tmp = i;
			}
		}
	}
	
	cout << tmp;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int64_t N;
    cin >> N;
    vector<int64_t> A(N), B(N), C(N);
    rep(i, 0, N){
        cin >> A.at(i);
        B.at(i) = (i + 1) - A.at(i);
        C.at(i) = (i + 1) + A.at(i);
    }
    
    map<int64_t,int64_t> mp_b, mp_c;
    rep(i, 0, N){
        if (mp_b.count(B.at(i))){
            mp_b.at(B.at(i))++;
        }
        else{
            mp_b[B.at(i)] = 1;
        }
        if (mp_c.count(C.at(i))){
            mp_c.at(C.at(i))++;
        }
        else{
            mp_c[C.at(i)] = 1;
        }
    }
    int64_t ans = 0;
    set<int64_t> s;
    rep(i, 0, N){
        int64_t x = B.at(i);
        if (s.count(x)) continue;
        s.insert(x);
        if (!mp_c.count(x)) continue;
        int64_t y = mp_b.at(x);
        int64_t z = mp_c.at(x);
        //cout << x << " " << y << " "<< z << endl;
        ans += y * z;
    }
    cout << ans << endl;
}
    
    


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

int main(){
  int n,k,ans=0;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  for(int i=0;i<k;i++)ans+=a[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 3628
#copy
a, b, c = map(int, input().split())
d = set([a, b, c])
print("Yes" if len(d) == 2 else "No")

# a = set(map(int, input().split())) 

#if len(a) == 2:
#   print("Yes")
#else:
#   print("No")

#こっちのがわかりやすいかも

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


int main() {
	int n,max=0;
	cin>>n;
	map<string,int>vote;
	char s[15];
	while(n--)
	{
		cin>>s;
		vote[s]++;
	}
	map<string,int >::iterator itr;
	
	for(itr=vote.begin();itr!=vote.end();itr++)
	{
		if(itr->second>max) max=itr->second;
	}
	
	for(itr=vote.begin();itr!=vote.end();itr++)
	{
		if(itr->second==max) cout<<itr->first<<endl;
	}
           
	return 0;
}

Measured memory_bytes: 19244
#include<cstdio>
#include<vector>
using namespace std;
typedef unsigned long long ull;

int main() {
	vector<ull> v;
	int k;
	scanf("%d", &k);
	for(int i=0;i<k;i++) {
		unsigned int a;
		scanf("%u", &a);
		v.push_back(a);
	}
	ull min = 2, max = 2;
	while(min <= max && !v.empty()) {
		unsigned int a = v.back();
		v.pop_back();
		ull x = (min + a - 1) / a;
		ull y = max / a;
		min = a * x;
		max = a * y + a - 1;
	}
	if(min > max) {
		printf("-1\n");
	} else {
		printf("%llu %llu\n", min, max);
	}
	return 0;
}



Measured memory_bytes: 1400
#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;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	string s;
	cin >> s;
	vector<int>r;
	vector<int>w;
	for (int i = 0; i < N; i++) {
		if (s[i] == 'W')w.push_back(i);
	}
	for (int i = N - 1; i >= 0; i--) {
		if (s[i] == 'R')r.push_back(i);
	}
	int ans = 0;
	M = min(r.size(), w.size());
	for (int i = 0; i < M; i++) {
		if (w[i] < r[i])ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4576
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    int t,a;cin>>t>>a;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    double d=10000;
    int ans=0;
    for(int i=0;i<n;i++){
        double t_ave = t - h[i]*0.006;
        d = min(d,abs(a-t_ave));
        ans=(d<abs(a-t_ave))? ans:i;
    }
    cout<<ans+1<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
int main(){
  int n, G[100][100], d[100], pi[100], color[100];
  int i, j, u, k, v, c, mincost, sum = 0;
 
  scanf("%d", &n);
 
  for(i = 0; i < n; i++) for(j = 0; j < n; j++) G[i][j] = -1;
 
  for(i = 0; i < n; i++){
    d[i] = INT_MAX;
    pi[i] = 0;
    color[i] = 0;
    scanf("%d%d", &u, &k);
    for(j = 0; j < k; j++){
      scanf("%d%d", &v, &c);
      G[u][v] = c;
    }
  }
 
  d[0] = 0;
 
  while(1){
    mincost = INT_MAX;
    for(i = 0; i < n; i++){
      if(color[i] != 1 && d[i] < mincost){
    mincost = d[i];
    u = i;
      }
    }
    if(mincost == INT_MAX) break;
    color[u] = 1;
    for(i = 0; i < n; i++){
      if(G[u][i] != -1 && color[i] != 1 && d[u] + G[u][i] < d[i]){
    pi[i] = u;
    d[i] = G[u][i];
    d[i] += d[pi[i]];
      }
    }
  }
 
  for(i = 0; i < n; i++) printf("%d %d\n", i, d[i]);
  return 0;
}

Measured memory_bytes: 640
# abc171_d.py
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
sums = sum(A)
Q = int(input())
for i in range(Q):
    b ,c = map(int,input().split())
    sums += C[b]*c
    sums -= C[b]*b
    C[c] += C[b]
    C[b] = 0
    print(sums)



Measured memory_bytes: 23996
#!/usr/bin/env python
# coding: utf-8

# In[15]:


N = int(input())
xy_list = []
for _ in range(N):
    A = int(input())
    xy = []
    for _ in range(A):
        xy.append(list(map(int, input().split())))
    xy_list.append(xy)


# In[16]:


ans = 0
for i in range(2**N):
    for j,a_list in enumerate(xy_list):
        if (i>>j)&1 == 1:
            for k,(x,y) in enumerate(a_list):
                if (i>>(x-1))&1 != y:
                    break
            else:
                continue
            break
    else:
        ans = max(ans, bin(i)[2:].count("1"))
print(ans)


# In[ ]:






Measured memory_bytes: 9192
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

const double pi=3.1415;
ll absc(ll a,ll b){return (a-b>0?a-b:b-a);
}
ll mini(ll a,ll b){return (a>b?b:a);}
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
}
ll gojou(ll n){return pow(n,5);}
int main()
{
   ll n;
   cin>>n;
   vector<ll>A(n);
   map<ll,ll>a;
   set<ll>aa;
   map<ll,ll>b;
   rep(i,n){
   	cin>>A[i];
   	a[i-A[i]]++;
   	b[i+A[i]]++;
   	aa.insert(i-A[i]);
   }
   ll ans=0;
   auto itr=aa.begin();
   rep(i,aa.size()){
   	ans+=(a[*itr]*b[*itr]);
   	itr++;
   }
   cout<<ans;
}


Measured memory_bytes: 47868
var
  n,i,sum,ans:longint;
  s:string;
begin
  sum:=0;
  readln(n);
  readln(s);
  for i:=1 to length(s) do
     begin
         if s[i]='I' then inc(sum);
         if s[i]='D' then dec(sum);
         if sum>ans then ans:=sum;
     end;
 writeln(ans);
end.


Measured memory_bytes: 128
s=list(input())
K=int(input())
S=s.copy()

if len(S)==1:
  print(K//2)
  exit()

pc=0
ju=0
for i in range(len(S)):
  if S[i]==S[0]:
    pc+=1
    if i==len(S)-1:
      ju=1
  else:
    break

lc=0
if ju==0 and S[0]==S[-1]:
  for i in reversed(range(len(S))):
    if S[i]==S[0]:
      lc+=1
    else:
      break
  
if S[0]==S[1]:
  S[0]="#"
for i in range(1,len(S)):
  if S[i-1]==S[i]:
    S[i]="#"

ans=S.count("#")
if pc%2==1 and pc>1:
  ans-=1
  
  
if ju==1 and len(S)%2==1:
  print((len(S)*K)//2)
  exit()
  
if s[-1]==s[0] and s[1]!=s[0] and s[-2]!=s[0]:
  print(K*ans+(K-1))
  exit()


if S[0]=="#" and pc%2==1 and lc%2==1 and ju==0:
  print(ans*K+K-1)
  exit()


print(ans*K)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;


public class Contest
{
	public static void Main()
	{

/*
		int n = a[0];
		int[][] e = new int[n][];
		for(int i=0; i<n; i++) MyRead.Array(out e[i]);

		int[] a;
		MyRead.Array(out a);

        long a,b,c,d,e,f;
        MyRead.Multi(out a, out b, out c, out d, out e, out f);

		Console.WriteLine(string.Join(' ', Array.ConvertAll(ans, x => x.ToString())));
*/

        string s;
		MyRead.Multi(out s);

		bool[] v = new bool[s.Length];
		int[] cnt = new int[s.Length];
		int[] ans = new int[s.Length];


		for(int i=0;i<v.Length; i++) v[i] = (s[i]=='R');
		for(int i=0;i<v.Length; i++) {
			if(i==0){
				for(int j=i;j<v.Length; j++){
					if(v[j]){
						cnt[i]++;
					}else{
						break;
					}
				}
			}else{
				if(v[i-1] && v[i]){
					cnt[i] = cnt[i-1]-1;
				}else if(v[i-1] && !v[i]){
					cnt[i] = -1;
				}else if(!v[i-1] && v[i]){
					for(int j=i;j<v.Length; j++){
						if(v[j]){
							cnt[i]++;
						}else{
							break;
						}
					}
				}else{
					cnt[i] = cnt[i-1]-1;
				}
			}
		}
		for(int i=0;i<v.Length; i++){
			int k=i+cnt[i];
			if(cnt[i]%2==1) {
				k--;
			} else if(cnt[i]%2==-1){
				k++;
			}
			ans[k]++;
		}


		Console.WriteLine(string.Join(" ", Array.ConvertAll(ans, x => x.ToString())));
	}


}

public static class MyRead
{
	private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
	private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
	private static T cv<T>(string s) => eq<T, int>()    ? ct<T, int>(int.Parse(s))
	                                  : eq<T, long>()   ? ct<T, long>(long.Parse(s))
	                                  : eq<T, double>() ? ct<T, double>(double.Parse(s))
	                                  : eq<T, char>()   ? ct<T, char>(s[0])
	                                                    : ct<T, string>(s);
	public static string[] Array<T>(out T[] a) {		
		var ar = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries); 												
		a = System.Array.ConvertAll(ar, new Converter<string,T>(cv<T>));
		return ar;
	}										
	public static string[] Multi<T>(out T a) {
		var ar = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries); 
		a = cv<T>(ar[0]);
		return ar;
	}
	public static string[] Multi<T, U>(out T a, out U b) {
		var ar = Multi<T>(out a); 
        b = cv<U>(ar[1]);
		return ar;
	}
	public static string[] Multi<T, U, V>(out T a, out U b, out V c) {
		var ar = Multi<T, U>(out a, out b); 
        c = cv<V>(ar[2]);
		return ar;
	}
	public static string[] Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
		var ar = Multi<T, U, V>(out a, out b, out c); 
        d = cv<W>(ar[3]);
		return ar;
	}
	public static string[] Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) {
		var ar = Multi<T, U, V, W>(out a, out b, out c, out d); 
        e = cv<X>(ar[4]);
		return ar;
	}
	public static string[] Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) {
		var ar = Multi<T, U, V, W, X>(out a, out b, out c, out d, out e); 
        f = cv<Y>(ar[5]);
		return ar;
	}
}




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

int prime(int x){
	for(int j=2;j*j<=x;j++){
		if(x%j==0){
			return 0;
		}
	}
	return 1;
}

int main(){
	int n,x,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		ans+=prime(x);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1160
//D - String Formation
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
    string s;
    int q;
    cin>>s>>q;

    int rev_cnt;
    int head=0;
    for(int i=0; i<q; i++){
        int query;
        cin>>query;

        
        if(query==1){
            //cout<<"now head :"<<head<<endl;
            //cout<<"now s : "<<s<<endl;
            if(head==0){
                head=s.size();
            }else{
                head=0;
            }
            //cout<<"reverse head : "<<head<<endl;
        }
        else if(query==2){
            int t;
            cin>>t;
            if(t==1){
                char c;
                cin>>c;
                if(head==0){
                    s.insert(s.begin(),c);
                }else{
                    s.insert(s.end(),c);
                }
            }else{
                char c;
                cin>>c;
                if(head==0){
                    s.insert(s.end(),c);
                }else{
                    s.insert(s.begin(),c);
                }                
            }
            //cout<<"insert s : "<<s<<endl;
        }
        //cout<<"test : "<<s<<endl;
    }
    
    if(head!=0){
        reverse(s.begin(),s.end());
    }
    
  
    cout<<s<<endl;
    return 0;

}

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

void solve(long long K, std::string S)
{
    cout << S.substr(0, K);
    if ((ll)S.size() > K) {
        cout << "...";
    }
    cout << "\n";
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
#pragma GCC diagnostic ignored "-Wunused-result"
int main(){
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(K, S);
    return 0;
}


Measured memory_bytes: 3692
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
#define PI 3.141592
using namespace std;

int main()
{
	int h, w, x, y;
	cin >> w >> h>> x >> y;

	printf("%.6f %d", (double)h * (double)w / 2.0, 2 * x == w && 2 * y == h ? 1 : 0);

	return 0;
}

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

#define I inline
#define fi first
#define se second
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(reg i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define bp __builtin_popcount
#define vi vector<int>
#define cr const reg&
using namespace std;
const int mod = 998244353, N = 1e6 + 1;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I int read() {
	reg x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(LL x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(LL x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(LL x) {put(x), putchar(' ');}
I void pr2(LL x) {put(x), puts("");}

I int pow_mod(reg a, reg k) {reg ans = 1; for(; k; k >>= 1, a = (LL)a * a % mod) if(k & 1) ans = (LL)ans * a % mod; return ans;}

LL C[61];
LL a[N], L[N], R[N];

int main() {
	reg n = read();
	fo(i, 0, n) a[i] = read();
	if(n == 0 && a[0] > 1) {puts("-1"); return 0;}
	C[0] = 1; fo(i, 1, 60) C[i] = C[i - 1] << 1;
	L[n] = R[n] = a[n];
	fd(i, n - 1, 0) {
		L[i] = L[i + 1] + 1 >> 1;
		R[i] = R[i + 1]; L[i] += a[i], R[i] += a[i];
		if(i > 60) continue;
		if(L[i] > C[i]) {puts("-1"); return 0;}
		R[i] = min(R[i], C[i]);
	} LL ans = 1, u = 1;
	fo(i, 1, n) {
		LL hh = min(R[i], u * 2);
		ans += hh;
		u = hh - a[i];
	} pr2(ans);
	return 0;
}




Measured memory_bytes: 5920