akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

struct mint {
  ll x;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {
  }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }

  /* 変数名.pow(n) */
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // 以降はMODが素数のみ
  mint inv() const {
    return pow(MOD - 2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

ostream& operator<<(ostream& s, const mint a) {
  s << a.x;
  return s;
}

/* a^n (MOD) の計算 O(log n) */
ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

// a^{-1} mod を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

signed main() {
  int N, K;
  cin >> N >> K;

  mint ans = 0;
  repp(k, K, N + 1) {
    int mn = k * (k - 1) / 2;
    int mx = k * (2 * N - k + 1) / 2;
    ans += mx - mn + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3652
#!/usr/bin/python3

import array
import math
import os
import sys


def main():
    A, B = read_ints()
    print(A * B if A <= 9 and B <= 9 else -1)


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a + b) / 2 << endl;
}



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

const int p = 1e9 + 7, inv = 5e8 + 4;

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

    int a, sum = 0, powsum = 0;
    for (int i = 0; i < n; ++i)
    {
        std::cin >> a;
        sum = (sum + a) % p;
        powsum = (powsum + 1ll * a * a % p) % p;
    }

    std::cout << ((1ll * sum * sum % p - powsum) % p + p) % p * inv % p << std::endl;
    return 0;
}

Measured memory_bytes: 3628
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	long n = sc.nextInt();
    	int a = sc.nextInt();
    	int b = sc.nextInt();
    	int p = 1000000007;

    	long ans = (modPow(2,n,p)-1-modCombination(n,a,p)-modCombination(n,b,p))%p;
    	if(ans>=0) {
    		System.out.println(ans);
    	} else {
        	System.out.println(ans+p);
    	}


    }
    public static final long modPow(long x, long n, final long mod) {
        long sum = 1;
        while (n > 0) {
            if ((n & 1) == 1) {      //ビットが立っていたら
                sum = sum * x % mod; //x^2^k1 * x^2^k2 * x^2^k3 * ・・・
            }
            x = x * x % mod;         //((x^2)^2)^2 ・・・
            n >>= 1;
        }
        return sum;
    }
    public static final long modCombination(long a, long b, final long mod) {
    	long P = 1;
    	for(long i=a;i>=a-b+1;i--) {
    		P = P*i%mod;
    	}
    	long F = 1;
    	for(long i=1;i<=b;i++) {
    		F = F*i%mod;
    	}

    	long modComb = P*modPow(F,mod-2,mod)%mod;
    	return modComb;
    }
}


Measured memory_bytes: 23636
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;

int main(){
    double x1, x2, y1, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    double z,k;
    z = pow( double ( x1-x2 ), 2) + pow( double ( y1-y2 ), 2);
    k = sqrt(z);
    printf("%lf\n", k);
    
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H.at(i);

  vector<int> dp(N);
  dp.at(1) = abs(H.at(0) - H.at(1));
  for (int i = 2; i < N; i++) {
    int x = dp.at(i - 2) + abs(H.at(i) - H.at(i - 2));
    int y = dp.at(i - 1) + abs(H.at(i) - H.at(i - 1));
    dp.at(i) = min(x, y);
  }

  cout << dp.at(N - 1) << "\n";
}

Measured memory_bytes: 1024
class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.rule={'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3)}
    def output(self):
        return self.dice
    def move(self, direction):
        for _ in direction:
            self.dice = [self.dice[y] for y in self.rule[_]]
        return self.dice

dice = Dice([int(x) for x in input().split()])
for _ in range(int(input())):
    tmp = [int(x) for x in input().split()]
    count = 0
    while dice.output()[0] != tmp[0]:
        if count > 4:
            while dice.output()[0] != tmp[0]: dice.move("E")
            break
        else:
            dice.move("N")
            count += 1

    while dice.output()[1] != tmp[1]: dice.move("ESW")
    print(dice.output()[2])


Measured memory_bytes: 5608
s = input()
alp = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
buf = ''
for i in alp:
    if not i in set(s):
        buf = i
        break
if buf:
    print(s+buf)
else:
    c = 1
    for i in range(1,len(s)):
        if s[-i-1]>s[-i]:
            c += 1
        else:break
    if c==26:
        print(-1)
    else:
        for i in sorted(s[-c:]):
            if ord(s[-c-1])<ord(i):
                buf = i
                break
        print(s[:-c-1]+buf)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		if (a < b & b < c){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}

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

bool check(int N, unordered_set<char>& D) {
  for (char n : to_string(N)) {
    if (D.count(n)) return false;
  }
  return true;
}

int main() {
  int N, K;
  cin >> N >> K;
  unordered_set<char> D;
  char d;
  for (int i = 0; i < K; i++) {
    cin >> d;
    D.insert(d);
  }
  while (true) {
    if (check(N, D)) {
      cout << N << endl;
      return 0;
    }
    N++;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <string>
#include <vector>
#include <list>

using namespace std;
int a(int A, int B, int C){

    int max_c = B / A;

    return min(max_c, C);


}

int b(int A, int B, int K){
    int count = 0;
    int i = 0;
    while(count < K){
        i++;
        if (A % i == 0 && B % i == 0){
            count++;
        }

    }

    return i;
}


int c(string S){


    int red_num = 0;
    int bl_num = 0;
    for(auto p = S.begin(); p != S.end(); p++){
        if (*p == '0'){
            red_num++;
        }else if(*p == '1' ){
            bl_num++;
        }
    }

    return 2*min(red_num, bl_num);



}

int main(){
    string S; cin >> S;

    cout << c(S);

    return 0;

}


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

#define T 1
#define F 0
#define N 3

int dx[4] = { 0,-1,0,1 };
int dy[4] = { 1,0,-1,0 };
int lim;
int p[N][N];

int huristic() {
	int i, j, n, sum = 0;
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			if (p[i][j] == 0)continue;
			n = p[i][j] - 1;
			sum += abs(n / N - i) + abs(n % N - j);
		}
	}
	return sum;
}

int dfs(int d, int pre, int y, int x) {
	int h = huristic();
	int i;
	if (h == 0)return T;
	if (lim < d + h) return F;
	
	for (i = 0; i < 4; i++) {
		if (abs(i - pre) == 2) continue;
		int tx = x + dx[i], ty = y + dy[i];
		if (tx < 0 || ty < 0 || tx >= N || ty >= N)continue;
		int tmp = p[ty][tx];
		p[ty][tx] = p[y][x];
		p[y][x] = tmp;

		if (dfs(d + 1, i, ty, tx))return T;
		tmp = p[ty][tx];
		p[ty][tx] = p[y][x];
		p[y][x] = tmp;
	}
	return F;
}

void PZL(int x, int y) {
	for (lim = 0;; lim++) {
		if (dfs(0, 99, y, x)) {
			printf("%d\n", lim);
			return;
		}
	}
}

int main() {
	int i,j;
	int x, y;

	for (i = 0; i < 3; i++) {
		for (j = 0; j < 3; j++) {
			scanf("%d", &p[i][j]);
			if (p[i][j] == 0) {
				y = i;x = j;
			}
		}
	}
	PZL(x, y);
	return 0;

}


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

int main()
{
  int k, s;
  cin >> k >> s;
  int count = 0;
  for (int x = 0; x <= k; ++x)
  {
    for (int y = 0; y <= k; ++y)
    {
      int z = s - x - y;
      if (0 <= z && z <= k)
      {
        count++;
      }
    }
  }
  cout << count << endl;
  //cout << k << " " << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

namespace {
	template<class T>
	struct Vec2
	{
		Vec2(T _x, T _y) : x(_x), y(_y) {}
		Vec2 operator+(const Vec2& rhs) const { return Vec2(x + rhs.x, y + rhs.y); }
		Vec2 operator-(const Vec2& rhs) const { return Vec2(x - rhs.x, y - rhs.y); }
		Vec2 operator*(const T t) const { return Vec2(x*t, y*t); }
		bool operator<(const Vec2& rhs) const { return x != rhs.x ? x < rhs.x : y < rhs.y; }
		T dot(const Vec2& rhs) const { return x*rhs.x + y*rhs.y; }
		T cross(const Vec2& rhs) const { return x*rhs.y - y*rhs.x; }
		T x, y;
	};

	typedef long long ll;
	typedef Vec2<ll> P;

	struct EndPoint
	{
		EndPoint(const pair<P, P>& _seg, bool _start) : seg(_seg), start(_start) {}
		bool operator<(const EndPoint& rhs) const { return cod().x < rhs.cod().x; }
		const P& cod() const { return start ? seg.first : seg.second; }

		pair<P, P> seg;
		bool start;
	};
}

static int countIntersection(const vector<EndPoint>& X)
{
	int num_int = 0;
	set<ll> Y;
	for (size_t i = 0; i < X.size(); i++) {
		const P& p0 = X[i].seg.first;
		const P& p1 = X[i].seg.second;
		if (p0.x == p1.x) {
			num_int += distance(Y.lower_bound(p0.y), Y.lower_bound(p1.y));
		}
		else if (X[i].start) {
			Y.insert(p0.y);
		}
		else {
			Y.erase(p0.y);
		}
	}

	return num_int;
}

int main()
{
	int n = 0;
	cin >> n;

	vector<EndPoint> X;
	for (int i = 0; i < n; i++) {
		int x1, y1, x2, y2;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		P a(x1, y1), b(x2, y2);
		if (b < a) {
			swap(a, b);
		}
		a = a * 4;
		b = b * 4;
		if (a.y == b.y) {
			a.x--;
			b.x++;
			X.push_back(EndPoint(make_pair(a, b), true));
			X.push_back(EndPoint(make_pair(a, b), false));
		}
		else {
			a.y--;
			b.y++;
			X.push_back(EndPoint(make_pair(a, b), false));
		}
	}
	sort(X.begin(), X.end());
	cout << countIntersection(X) << endl;
	return 0;
}


Measured memory_bytes: 13360
#include<bits/stdc++.h>
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
	int n,g=0;
	cin>>n;
	string s=to_string(n);
	for(int i=0;i<s.size();i++)
	g+=(s[i]-'0');
	cout<<(n%g?"No\n":"Yes\n");
    return 0;
}


Measured memory_bytes: 3712
MOD = 10 ** 9 + 7

L = list(input())

N = len(L)

OK = [0] * (N + 1)
JUST = [0] * (N + 1)
JUST[0] = 1

for i in range(N):
    if L[i] == '1':
        OK[i + 1] = (OK[i] * 3 + JUST[i]) % MOD
        JUST[i + 1] = (JUST[i] * 2) % MOD
    else:
        OK[i + 1] = (OK[i] * 3) % MOD
        JUST[i + 1] = (JUST[i]) % MOD

print ((OK[-1] + JUST[-1]) % MOD)

Measured memory_bytes: 11796
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0;i<n;i++) {
            set.add(sc.nextInt());
        }
        if (set.size() == n) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }
}


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

#define MAX 10000
#define NIL -1

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

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

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

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

int getSibling(int u) {
    if (T[u].parent == NIL) return NIL;
    if (T[T[u].parent].left != u && T[T[u].parent].right != NIL) return T[T[u].parent].left;
    if (T[T[u].parent].right != u && T[T[u].parent].left != NIL) return T[T[u].parent].right;
    return NIL;
}

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

    if ( T[u].parent == NIL ) {
        printf("root\n");
    } else if ( T[u].left == NIL && T[u].right == NIL ) {
        printf("leaf\n");
    } else {
        printf("internal node\n");
    }
}

int main(void) {
    int v, l, r, root = 0;
    cin >> n;
    for (int i = 0; i < n; i++) T[i].parent = NIL;

    for (int i = 0; i < n; i++) {
        cin >> v >> l >> r;
        T[v].left = l;
        T[v].right = r;
        if ( l != NIL ) T[l].parent = v;
        if ( r != NIL ) T[r].parent = v;
    }

    for (int i = 0; i < n; i++) if ( T[i].parent == NIL) root = i;

    setDepth(root, 0);
    setHeight(root);

    for (int i = 0; i < n; i++) print(i);

    return 0;
}


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

int getmd(int a,int b,int c,int d){
    return abs(a-c)+abs(b-d);
}

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

    ans = a+b;
    ans = max(ans,a-b);
    ans = max(ans,a*b);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    int ans = 0;
    for (int i = 1; i <= N; i++) {
      if (oddNumber(i)) {
        ans++;
      }
    }
    
    System.out.println(ans);
  }
  
  private static boolean oddNumber(int n) {
    int keta = 0;
    while (n != 0) {
      n /= 10;
      keta++;
    }
    return keta % 2 == 1;
  }
}

Measured memory_bytes: 21972
a, b, k = map(int, input().split())
m = [a, b]

cnt = 0
while True:
    turn = cnt % 2
    if m[turn] % 2 == 1:
        m[turn] -= 1
    m[turn] //= 2
    m[(turn + 1) % 2] += m[turn]
    cnt += 1
    if cnt == k:
        break

print(*m)

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

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[][] player=new int[n][3];

		int[][] player1=new int[n][3];
		int[] point=new int[n];
		for(int i=0;i<n;i++){
			for(int j=0;j<3;j++){
				player[i][j]=sc.nextInt();
				player1[i][j]=player[i][j];
			}
		}

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

				for(int i=0;i<n;i++){
					for(int k=0;k<n;k++){
						if(player[i][j]==player[k][j]&&i!=k){
							player1[k][j]=0;
							player1[i][j]=0;
						}else{

						}
						//System.out.printf("[%d]\n",player[k][j]);

					}
				}
			}
		for(int i=0;i<n;i++){
			for(int j=0;j<3;j++){
				//System.out.printf("[%d]\n", player[i][j]);
				point[i]+=player1[i][j];
			}
		}
		for(int i=0;i<n;i++){
		System.out.printf("%d\n", point[i]);
		}
	}

}

Measured memory_bytes: 29948
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<vector>

using namespace std;

#define LL long long

priority_queue<int>pq;

int main() {
	string com;
	while(1){
		cin>>com;
		if(com=="end")break;
		if(com=="extract"){
			cout << pq.top() << endl;
			pq.pop();
		}
		else{
			int x;
			cin>>x;
			pq.push(x);
		}
	}
	return 0;
}





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


int main() {
    int n; cin>>n;
    vector<int> ans(n,0);
    rep(i,n-1){
        int a; cin>>a;
        ans[a-1]++;
    }
    rep(i,n){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 4060
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int Maxn = 60;

ll x[Maxn], y[Maxn];

int main(){
    int i, j, k, l, n, m, p;
    cin >> n >> m;

    for (int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    
    ll ans = LONG_LONG_MAX;
    REP(i, n)REP(j, n)REP(k, n)REP(l, n){
        ll cnt = 0;
        REP(p, n) if (x[i] <= x[p] && x[p] <= x[j] && y[k] <= y[p] && y[p] <= y[l]) cnt++;
        if (cnt >= m) ans = min(ans, (x[j] - x[i]) * (y[l] - y[k]));
    }

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

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vector<ll> c(N-1), s(N-1), f(N-1);
    rep(i, N-1) cin >> c[i] >> s[i] >> f[i];
    rep(i, N-1){
        ll res = 0;
        Rep(j, i, N-1){
            if(res < s[j]){
                res = s[j];
            }else{
                if(res%f[j]){
                    res = (res/f[j] + 1)*f[j];
                }
            }
            res += c[j];
        }
        cout << res << endl;
    }

    cout << 0 << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
mod = 10**9+7
n = 10**6

def comb(n, r):
    if 2 * r > n: return comb(n, n-r)
    return fac[n] * inv[r] * inv[n-r] % mod

x, y = map(int, input().split())
if (x+y) % 3 != 0:
  print(0)
  exit()
     
a = -(x-2*y)//3
b = (2*x-y)//3 
if a<0 or b<0:
  print(0)
  exit()
  
fac = [1] * (n+2)
inv = [1] * (n+2)
for i in range(2, n+1):
    fac[i] = fac[i-1] * i % mod
inv[n] = pow(fac[n], mod - 2, mod)
for i in range(n-1, 1, -1):
    inv[i] = inv[i + 1] * (i + 1) % mod
  
print(comb(a+b, a) % mod)

Measured memory_bytes: 82164
#include <iostream>
using namespace std;
int main(void){
    
    int a=0,b=0,k=0;
    
    cin>>a>>b>>k;
    
    while(k>0){
        if(a%2!=0) a-=1;
        b+=(a/2);
        a/=2;
        
        --k;
        if(k<=0) break;
        //cout<<a<<" "<<b<<" "<<k<<endl;
        
        if(b%2!=0) b-=1;
        a+=(b/2);
        b/=2;
        
        --k;
        //cout<<a<<" "<<b<<" "<<k<<endl;
    }
    cout<<a<<" "<<b<<endl;
    
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(java.util.Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: java.util.Scanner, pw: java.io.PrintWriter) {
        val K = sc.next().toInt()

        var a = listOf<Long>(1, 2, 3, 4, 5, 6, 7, 8, 9)
        var k = K
        while (k > 0) {
            if (k < a.count()) {
                pw.println(a[k - 1])
                return
            }
            val old = a
            a = old.flatMap { n ->
                val last = n % 10
                val nn = mutableListOf<Long>()
                if (last - 1 >= 0) nn.add(n * 10 + last - 1)
                nn.add(n * 10 + last)
                if (last + 1 <= 9) nn.add(n * 10 + last + 1)
                nn
            }
            k -= old.count()
        }
        pw.println(a[0])
    }
}


Measured memory_bytes: 46296
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[100009];
int ans=-1,mx;
int main()
{
	scanf("%d%d",&n,&k);
	for(int j=1;j<=n;j++)
		scanf("%d",&a[j]);
	for(int j=1;j+k-1<=n;j++)
	{
		if(a[j]<0 && a[j+k-1]>0) mx=abs(a[j])+a[j+k-1]+min(abs(a[j]),a[j+k-1]);
		else mx=max(abs(a[j]),abs(a[j+k-1]));
		if(mx<ans || j==1) ans=mx;
	}
	printf("%d",ans);
	return 0;
}

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

signed main() {
  string S;
cin >> S;

string T;
T = "CODEFESTIVAL2016";

int ans = 0;
for( int i = 0; i < S.size(); i++ ){
if( S.at(i) != T.at(i) ) ans++;
}
cout << ans << endl;
      
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(void){
    int N;
    string s;
    cin>>N>>s;
    int xmax = 0;
    int x = 0;
    FOR(i, 0, N){
        if(s[i]=='I') x++;
        else if(s[i]=='D') x--;
        xmax = max(xmax,x);
    }
    cout << xmax << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];
	vector<ll> res(n);
	ll sum = 0;
	rep(i, n) {
		sum += b[i];
		res[i] = a[i] + b[i];
	}
	sort(rall(res));
	ll ans = 0;
	rep(i, n) {
		if (i % 2 == 0) ans += res[i];
	}
	cout << ans - sum << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int N, L; cin >> N >> L;
  vi arr(N);
  rep(i,N) cin >> arr[i];

  int pos = -1;
  rep(i,N-1) {
    if (arr[i] + arr[i+1] >= L) {
      pos = i;
      break;
    }
  }

  if (pos == -1) {
    cout << "Impossible\n";
    return 0;
  }

  cout << "Possible\n";

  for (int i=0; i<pos; ++i) cout << i+1 << endl;
  for (int i=N-1; i>pos; --i) cout << i << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <sstream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
 
int main(){
  int N,K;
  cin>>N>>K;
  vector<int> A(N,0);
  for(int i=0;i<N;++i){
    cin>>A[i];
  }
  
  int total=0;
  for(int i=0;i<N;++i){
    total+=A[i];
  }
  
  for(int div=1;div<=total/2;++div){
    if(total%div!=0){
      continue;
    }
    vector<int> mod(N,0);
    int num=total/div;
    for(int i=0;i<N;++i){
      mod[i]=A[i]%num;
    }
    
    sort(mod.begin(),mod.end());
    int count=0;
    while(count<=K){
      if(mod.size()==0){
        cout<<num<<endl;
        return 0;
      }else if(mod[0]==0){
        mod.erase(mod.begin());
        continue;
      }
      int step=min(mod[0],num-mod[mod.size()-1]);
      count+=step;
      mod[0]-=step;
      if(mod[0]==0){
        mod.erase(mod.begin());
      }
      mod[mod.size()-1]+=step;
      if(mod[mod.size()-1]==num){
        mod.erase(mod.end()-1);
      }
    }
  }
  cout<<"1"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w",stdout);
    #endif
     int a;
     string s;
     cin>>a;
     cin>>s;
     if(s.size()<=a) cout<<s;
     else{
         for(int i=0;i<a;i++){
             cout<<s[i];
         }
         cout<<"...";
     }
}

Measured memory_bytes: 3536
import sys
from pprint import pprint

def solve(n):
    for i in range(1, n):
         edges = []
         for j in range(i+1, n+1):
             for k in range(9):
                 if i % (2**(k+1)) != j % (2**(k+1)):
                     # print(i, j, k+1)
                     edges.append(k+1)
                     break
         print(" ".join(map(str,edges)))

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    solve(n)

Measured memory_bytes: 43868
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 200100;
string S;
int N;
ll result;
map<char, int> deg;
int main() {

  cin >> S;
  N = S.size();

  result = (ll) N * (N + 1) / 2;
  for (int i = 0; i < S.size(); i++){
    deg[S[i]]++;
  }
  ll tmp = 0;
  for (char i = 'a'; i <= 'z'; i++){
    tmp += (ll)deg[i] * (deg[i] + 1) / 2;
  }
  cout << result - tmp + 1<< endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
    int n = 0, m = 0;
    cin >> n >> m;
    
    vector<int> pos(m, 0);
    for(int i = 0; i < m; ++i) {
        cin >> pos[i];
    }
    sort(pos.begin(), pos.end());
    
    vector<int> diff;
    for(int i = 1; i < pos.size(); ++i) {
        diff.push_back(pos[i] - pos[i - 1]);
    }
    sort(diff.begin(), diff.end());
    
    int ret = pos[m - 1] - pos[0];
    for(int i = 0; i < min(int(diff.size()), n - 1); ++i) {
        ret -= diff[diff.size() - 1 - i];
    }
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	ll n; cin >> n;
	ll ans = 1e18;
	for (ll i = 1; i*i <= n; i++) {
		if (n%i != 0) continue;
		ans = min(ans, i + n / i - 2);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll n=in();
    string foo=string(n,'a');
    string bar(n,'a');iota(bar.begin(),bar.end(),'a');
    while(true){
        cout<<foo<<endl;
        if(foo==bar)break;
        for(int i=foo.length()-1;i>0;--i){
            bool kuriage=true;
            for(int j=0;j<i;++j)kuriage&=foo[j]<foo[i];
            if(kuriage){
                foo[i]='a';
            }else{
                ++foo[i];
                break;
            }
        }
    }
}


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

using namespace std;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

struct BiConnectedComponents
{
  UnionFind uf;
  vector< vector< int > > g;
  vector< pair< int, int > > edges;
  vector< int > used, ord, low, comp;

  BiConnectedComponents(size_t v) : uf(v), g(v), used(v, 0), comp(v), ord(v), low(v)
  {
  }

  void add_edge(int x, int y)
  {
    g[x].push_back(y);
    g[y].push_back(x);
    edges.push_back(minmax(x, y));
  }

  void dfs(int idx, int &k, int par = -1)
  {
    used[idx] = true;
    ord[idx] = k++;
    low[idx] = ord[idx];

    for(auto &to : g[idx]) {
      if(!used[to]) {
        dfs(to, k, idx);
        low[idx] = min(low[idx], low[to]);
        if(ord[idx] >= low[to]) uf.unite(idx, to);
      } else if(to != par) {
        low[idx] = min(low[idx], ord[to]);
      }
    }
  }

  int operator[](int k)
  {
    return (comp[k]);
  }

  size_t size()
  {
    return (g.size());
  }

  void build(vector< vector< int > > &t)
  {
    int kk = 0;
    dfs(0, kk);

    int ptr = 0;
    vector< int > cc(g.size());
    for(int i = 0; i < g.size(); i++) {
      if(i == uf.find(i)) cc[i] = ptr++;
    }

    t.resize(ptr);
    for(int i = 0; i < g.size(); i++) {
      comp[i] = cc[uf.find(i)];
    }
    for(auto &e : edges) {
      int x = comp[e.first], y = comp[e.second];
      if(x == y) continue;
      t[x].push_back(y);
      t[y].push_back(x);
    }
  }
};

int N, M, W[100000];
vector< vector< int > > g;
vector< int > weightSum, sz;
int dp1[100000], dp3[100000];

int rec(int idx, int par = -1)
{
  int ret = 0;
  for(auto &to : g[idx]) {
    if(to == par) continue;
    ret = max(ret, rec(to, idx));
    dp1[idx] += dp1[to];
  }
  ret += weightSum[idx];
  if(sz[idx] >= 3 || dp1[idx] > 0) dp1[idx] += weightSum[idx];
  for(auto &to : g[idx]) {
    if(to == par) continue;
    else ret = max(ret, dp1[idx] - dp1[to] + dp3[to]);
  }
  return (dp3[idx] = ret);
}

int main()
{
  scanf("%d %d", &N, &M);
  BiConnectedComponents tree(N);
  for(int i = 0; i < N; i++) {
    scanf("%d", &W[i]);
  }
  while(M--) {
    int U, V;
    scanf("%d %d", &U, &V);
    tree.add_edge(--U, --V);
  }
  tree.build(g);
  weightSum.assign(g.size(), 0);
  sz.assign(g.size(), 0);
  for(int i = 0; i < N; i++) {
    weightSum[tree[i]] += W[i];
    sz[tree[i]]++;
  }
  printf("%d\n", rec(tree[0]));
}

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


int main()
{
	int n,lc=0,rc=0,i,j=-1;
	scanf("%d",&n);
	char a[100];
	scanf("%s",a);
	char stack[n];
	stack[++j]=a[0];
	for(i=1;i<n;i++)
	{
		
		if(a[i]==')'&&stack[j]=='('&&j!=-1)
			j--;
		else
			stack[++j]=a[i];
	}
	for(i=0;i<=j;i++)
		if(stack[i]==')')
			printf("(");
		printf("%s",a);
	for(i=0;i<=j;i++)
		if(stack[i]=='(')
			printf(")");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll

int n,m;
P a[51],b[51];

void solve(int k){
    P d = a[k];
    int dist = INF;
    int ans;
    REP(i,m){
        int td = abs(d.fi-b[i].fi) + abs(d.se-b[i].se);
        if(td<dist) ans = i+1, dist = td;
    }
    printf("%d\n",ans);
}

signed main(){
    scanf("%d%d",&n,&m);
    REP(i,n){
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        a[i] = mp(t1,t2);
    }
    REP(i,m){
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        b[i] = mp(t1,t2);
    }

    REP(i,n) solve(i);
    return 0;
}

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

int main(void) {
  int N;
  string S;

  cin >> N;
  cin >> S;

  int a=0, b=0, ans=0;
  for(int i=0;i<N;i++) {
    if(S.at(i)=='A') { 
      a=1;
      b=0;
    }
    else if(a==1&&b==0&&S.at(i)=='B') {
      a=1;
      b=1;
    }
    else if(a==1&&b==1&&S.at(i)=='C') { 
      ans++;
      a=0;
      b=0;
    }
    else {
      a=0;
      b=0;
    }
  }

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main(){
      int a, b, c;
      cin >> a >> b >> c;
      int tmp;
      tmp = b+c-a;
      cout << ((tmp<0) ? 0 : tmp) << endl;
      //else cout << b << endl;
     
      return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

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

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

	if(a == b) cout << 'H' << endl;
	else cout << 'D' << endl;

	return 0;
}

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

int main() {
  int a;
  int s1;
  int s2;
  int s3;
  
  cin >> a;
  
  s1=a/100;
  s2=a/10-s1*10;
  s3=a-s1*100-s2*10;
  
  cout << s1+s2+s3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N , M;
	cin >> N >> M;
	int total = 0;
	int nbOk = 0;
	bool ok[N];
	int nb[N];
	for (int i = 0 ; i < N ; i++)
	{
		ok[i] = false;
		nb[i] = 0;
	}
	for (int i = 0 ; i < M ; i++)
	{
		int a;
		string s;
		cin >> a>>s;
		if (s == "WA")
		{
			nb[a-1]++;
		}
		else
		{
			if (!ok[a - 1])
			{
				nbOk++;
				total += nb[a-1];
				ok[a-1] = true;
			}
		}
	}
	cout<<nbOk <<" "<<total<<endl;
}

Measured memory_bytes: 768
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
for i in range(N): 
   if S[i]=='R':
       S[i] =1
   elif S[i]=='G':
       S[i] =2
   elif S[i]=='B':
       S[i] =4
for i in range(N): 
   for j in range(i+1,N):
     k=2*j-i
     if k>=N : 
       continue  
     if S[i]+S[j]+S[k]==7 : 
         ans-=1 
print(ans)


Measured memory_bytes: 9120
fun main(args: Array<String>?): Unit {
    println(
            solve(IntArray(readLine()!!.trim().toInt()){ readLine()!!.trim().toInt()}).joinToString("\n")
    )
}



fun solve(numbers: IntArray): List<Int> {
    val memo = HashMap<Long, Int>()
    fun solve(value: Long): Int {
        return if (value < 10) 0
        else if (memo.containsKey(value)) memo[value]!!
        else {
            memo[value] = -1
            val r = solve((0 .. Math.log10(value.toDouble()).toInt()).map{digit -> exp10(digit).let{d -> (value / d) * (value % d)}}.max()!!).takeIf{it >= 0}
            if (r != null) {
                memo.replace(value, r + 1)
                r + 1
            }else -1
        }
    }
    val r = numbers.map{solve(it.toLong())}
    return r
}
fun exp10(e: Int): Long {
    return when(e){
        0 -> 1L
        1 -> 10L
        else -> exp10(e / 2).let{it * it * exp10(e % 2)}
    }
}


Measured memory_bytes: 31908
// SeeAlso: https://atcoder.jp/contests/abc124/tasks/abc124_d

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <limits>

#define MAX 4

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

using namespace std;

int main() {
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;

    int left = 0, right = 0, k = 0, sum = 0, ans = 0;

    while (right < N) {
        while (right < N && k < K) {
            if (S[right] == '0' && S[right + 1] == '1') {
                k++;
            }
            right++;
            sum++;
        }
        while (S[right] == '1') {
            right++;
            sum++;
        }
 
        ans = max(ans, sum);
        
        while (k == K) {
            if (S[left] == '0' && S[left + 1] == '1') {
                k--;
            }
            left++, sum--;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
def pow(x,n)
  if n == 0
    1
  elsif n % 2 == 0
    pow(x*x%MOD, n/2) % MOD
  else
    x * pow(x, n-1) % MOD
  end
end
MOD = 1000000007
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
sum = 0
a.each do |x|
  sum += x
  sum %= MOD
end
ans = 0
a.each do |x|
  v = sum - x
  v %= MOD
  ans += x * v
  ans %= MOD
end
ans = ans * pow(2,MOD-2) % MOD
puts ans

Measured memory_bytes: 30228
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int INF = 1e9;
const int MOD = 1000000007;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  
  rep(i,n+1){
    rep(j,m+1){
      int x=i;
      int y=j;
      if(m*x+n*y-2*x*y==k){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No"<< endl;
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,i,k,j;
   cin>>n>>k;
   int h[n],dp[n];
   for(int i = 0;i<n;i++)
   	 cin>>h[i];
     dp [0] =0;
     dp [1] =abs(h[1]-h[0]);
    for(i=2;i<n;i++)
    {
      int  maximum = 1000000000;
 
        // dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        for(j=1;j<=k && (i-j)>=0;j++)
        {
            maximum = min(maximum,dp[i-j]+abs(h[i]-h[i-j]));
        }
        dp[i] = maximum;
      }
    
    cout<<dp[n-1];
    return 0;
 
    }


Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}


void solve() {
    int N; cin >> N;

    int A[10][10] = {};

    long long ans = 0;
    for (int i = 1; i <= N; i++) {
        string s = to_string(i);

        int head = s[0] - '0';
        int tail = s[s.size()-1] - '0';

        if (head == tail) ans++;

        ans += A[tail][head] * 2;

        A[head][tail]++;
    }

    cout << ans << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 384
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 併合
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]
    
n,m=map(int,input().split())
uf=WeightedUnionFind(n)
for i in range(m):
    a,b,c=map(int,input().split())
    if not uf.same(a,b):
        uf.union(a,b,c)
    else:
        if uf.diff(a,b)!=c:
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 10236
a = list(map(int, input("").split()))
k=int(input())
m=0
if a[1] >= a[0] or a[2] >= a[0]:
    if a[2] >= a[1]:
        m=2
    else:
        m=1
for i in range(k):
    a[m]=a[m]*2
print(a[0]+a[1]+a[2])

Measured memory_bytes: 9096
dg = input().split(' ');
d = int(dg[0]);
g = int(dg[1]);
p = [0]*d;
c = [0]*d;
for i in range(d) :
    s = input().split(' ');
    p[i] = int(s[0]);
    c[i] = int(s[1]);

ans = sum(p);
for i in range(2**d) :
    sumpoint = 0;
    luck = -1;
    point = 0;
    for j in range(d-1,-1,-1) :
        if((i & 2**j)>>j) :
            sumpoint += (j+1)*100*p[j] + c[j];
            point += p[j];
        elif(luck<0) :
            luck = j
    k = 0;
    while k < p[luck] and sumpoint < g :
        sumpoint += (luck+1)*100;
        point += 1;
        k+= 1;
    if sumpoint >= g and point < ans :
        ans = point;

print(ans);

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

std::vector<size_t> make_vector(size_t n, size_t x) {
  return std::vector<size_t>(n, x);
}

template <class Tp>
std::vector<Tp> make_vector(size_t n, const Tp& x) {
  return std::vector<Tp>(n, x);
}

template <class... Ts>
auto make_vector(size_t n, size_t m, const Ts&... x) {
  return std::vector<decltype(make_vector(m, x...))>(n, make_vector(m, x...));
}

int main() {
  size_t N;
  scanf("%zu", &N);

  auto a = make_vector(N, N, intmax_t(0));
  for (auto& ai: a)
    for (auto& aij: ai)
      scanf("%jd", &aij);

  size_t M = 1 << N;
  std::vector<intmax_t> dp(M);
  for (size_t i = 1; i < M; ++i) {
    intmax_t cur = 0;
    for (size_t j = 0; j < N; ++j)
      for (size_t k = 0; k < j; ++k)
        if ((i >> j & 1) && (i >> k & 1))
          cur += a[j][k];

    dp[i] = cur;
    for (size_t j = i; (j = (j-1) & i);) {
      dp[i] = std::max(dp[i], dp[j]+dp[i^j]);
    }
  }

  printf("%jd\n", dp[M-1]);
}


Measured memory_bytes: 768
# 1. 入力をプログラムで扱えるように受け取ること
a, b = map(int, input().split())
# print(a, b)

# 2. 受け取った入力値を使って、適切に計算すること
answer = a * b

# 3.計算した結果を出力
print(answer)


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

using namespace std;
typedef long long ll;
const int MAXN = 200100;

int N;
string s;
int ans[MAXN];

bool wolo()
{
    for (int i = 1; i <= N + 1; i++)
    {
        int av = 0;
        if (s[i] == 'x') av = 1;
        ans[i+1] = (av + ans[i] + ans[i-1]) % 2;
        if (i + 1 >= N && ans[i+1] != ans[i+1-N]) return false;
    }
    return true;
}

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> s;
    s += s;

    for (int i = 0; i < 4; i++)
    {
        ans[0] = i % 2;
        ans[1] = i / 2;

        if (wolo())
        {
            for (int j = 0; j < N; j++)
            {
                if (ans[j]) cout << 'W';
                else cout << 'S';
            }
            cout << "\n";
            return 0;
        }
    }
    cout << "-1\n";
}

Measured memory_bytes: 1132