akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#define y0 qvya13579
#define y1 qvyb24680
#define j0 qvja13579
#define j1 qvjb24680
#define next qvne13579xt
#define prev qvpr13579ev
#define INF 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define IOS cin.tie(0);ios::sync_with_stdio(false)
#define M_P make_pair
#define P_B push_back
#define U_B upper_bound
#define L_B lower_bound
#define P_Q priority_queue
#define FIR first
#define SEC second
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP_R(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define FOR_R(i,m,n) for(int i=((int)(m)-1);i>=(int)(n);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZ(x) ((int)(x).size())
#define COUT(x) cout<<(x)<<endl
#define CIN(x) cin>>(x)
#define CIN2(x,y) cin>>(x)>>(y)
#define CIN3(x,y,z) cin>>(x)>>(y)>>(z)
#define CIN4(x,y,z,w) cin>>(x)>>(y)>>(z)>>(w)
#define SCAND(x) scanf("%d",&(x))
#define SCAND2(x,y) scanf("%d%d",&(x),&(y))
#define SCAND3(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))
#define SCAND4(x,y,z,w) scanf("%d%d%d%d",&(x),&(y),&(z),&(w))
#define SCANLLD(x) scanf("%lld",&(x))
#define SCANLLD2(x,y) scanf("%lld%lld",&(x),&(y))
#define SCANLLD3(x,y,z) scanf("%lld%lld%lld",&(x),&(y),&(z))
#define SCANLLD4(x,y,z,w) scanf("%lld%lld%lld%lld",&(x),&(y),&(z),&(w))
#define PRINTD(x) printf("%d\n",(x))
#define PRINTLLD(x) printf("%lld\n",(x))
typedef long long int lli;
using namespace std;

int ctoi(char c)
{
  if( c >= '0' and c <= '9' )
    {
      return (int)(c-'0');
    }

  return -1;
}

int alphabet_pos(char c) 
{
  if( c >= 'a' and c <= 'z' )
    {
      return (int)(c-'a');
    }

  return -1;
}


int alphabet_pos_capital(char c)
{
  if( c >= 'A' and c <= 'Z' )
    {
      return (int)(c-'A');
    }

  return -1;
}


vector<string> split(string str, char ch)
{
  int first = 0;
  int last = str.find_first_of(ch);
  
  if(last == string::npos)
    {
      last = SIZ(str);
    }

  vector<string> result;

  while( first < SIZ(str) )
    {
      string Ssubstr(str, first, last - first);
      result.push_back(Ssubstr);
      first = last + 1;
      last = str.find_first_of(ch, first);

      if(last == string::npos)
	{
	  last = SIZ(str);
	}
    }
  
  return result;
}

/*--------------- the end of the template --------------------*/









int main()
{
  //IOS; /* making cin faster */
  int R;
  SCAND(R);

  if( R < 1200 )
    {
      printf("ABC\n");
      
    }
  else if( R < 2800 )
    {
      printf("ARC\n");
      
    }
  else
    {
      printf("AGC\n");
      
    }

  

}


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

#define rep(i, n)  for (int i = 0; i < (int) (n); i++)
#define Rrep(i, n) for (int i = ((int) n - 1); i >= 0; i--)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
#define INF 2e15
#define MOD 10e9 + 7

typedef vector <int> vint;
typedef long long    ll;



int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int n;
    ll  sum   = 0;
    int index = 0;
    int ans   = 0;
    ll  add   = 0;
    cin >> n;
    vector <ll> len(n, 0);
    rep(i, n) {
        cin >> len.at(i);
        sum += len.at(i);
    }
    while (1) {
        add += len.at(index);
        if (add >= sum / 2) {
            break;
        }
        index++;
    }
    cout << min(abs(sum - 2 * add + 2 * len.at(index)), abs(sum - 2 * add)) << endl;

    return 0;
}


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

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

using namespace std;

int main(){
	int n,k; scanf("%d%d",&n,&k);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	for(int i=k;i<n;i++){
		puts(a[i]>a[i-k]?"Yes":"No");
	}

	return 0;
}


Measured memory_bytes: 4048
def examA():
    S = SI()
    if S[2]==S[3] and S[4]==S[5]:
        print("Yes")
    else:
        print("No")
    return

def examB():
    X = I()
    ans = 0
    ans += (X//500) * 1000
    X %= 500
    ans += (X//5) * 5
    print(ans)
    return

def examC():
    K, N = LI()
    A = LI()
    L = [0]*N
    L[0] = K-A[-1] + A[0]
    for i in range(1,N):
        L[i] = A[i]-A[i-1]
    ans = sum(L) - max(L)
    #print(L)
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examC()

"""

"""

Measured memory_bytes: 26836
/*.....Bismillahir Rahmanir Rahim.....*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld long double
#define   pb push_back
#define   sz(x)  (int)x.size()
#define   ff first
#define   ss second
#define   pii  pair<int,int> 
#define   pb  push_back
#define   eb  emplace_back
#define   lcm(a,b)  (a*b)/gcd(a,b)
using namespace std;

const int inf=10000000;
signed main(){
	map <pii,int> mp; 
	int n,m;
	cin>>n>>m;
	int a[1001],b[1001],c[1001],dist[1001][1001];	
	for(int i=1;i<=m;++i) { 
		cin>>a[i]>>b[i]>>c[i] ; 
		if (mp[{a[i],b[i]}] ) 
			mp[{a[i],b[i]}] = mp[{b[i],a[i]}] = min(mp[{a[i],b[i]}],c[i]);
		else 
			mp[{a[i],b[i]}] = mp[{b[i],a[i]}] = c[i] ; 
	} 
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			if(i==j) dist[i][j]=0;
			else dist[i][j]=inf;
		}
	}
	for(int i=1;i<=m;++i){
		dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);			dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
	}
	for(int k=1;k<=n;++k){
		for(int i=1;i<=n;++i){
			for(int j=1;j<=n;++j){
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			if(mp[{i,j}]) {
				if ( mp[{i,j}] > dist[i][j] ) ans++; 
			}
		}
	}
	cout<<ans/2<<endl;
}
/*
3 3
1 2 1
1 3 1
2 3 3

*/

Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;


int main() {
	int N;
	cin >> N;
	vector<vector<int>> sum(2, vector<int>(N + 1, 0));
	Rep(i, 2)Rep(j, N) {
		cin >> sum[i][j+1];
		sum[i][j + 1] += sum[i][j];
	}
	int res = 0;
	Rep(i, N) {
		int cn = 0;
		cn += (sum[0][i + 1] - sum[0][0]) + (sum[1][N] - sum[1][i]);
		if (res < cn) res = cn;
	}
	cout << res << endl;
	return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    int N;cin>>N;
    int res = 0;
    for(int i = 11; i <= N; i+= 2){
        
        int tmp = 0;
        for(int j = 1; j <= sqrt(i); j++){
            if(i%j==0)tmp+=2;
        }
        //cout<<tmp<<endl;
        if(tmp==8)res++;
    }
    cout<<res<<endl;
}




Measured memory_bytes: 256
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")
rgb = r*g*b

for i in range(n-1):
  for j in range(i+1,n):
    k = 2*j-i
    if k > n-1 or s[i] == s[j] or s[i] == s[k] or s[j] == s[k]: continue
    rgb -= 1
print(rgb)

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

int main(){
    int k, n;
    int memo[200010] = {};
    cin >> n >> k;

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

    int ans = 0;
    priority_queue<int> que;

    for(int i = 0;i < 200010;i++){
        que.push(memo[i]);
    }

    int cnt = 0;
    while(!que.empty()){
        int num = que.top();
        que.pop();

        if(num == 0) break;

        if(cnt < k){
            cnt++;
        }else{
            ans += num;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2168
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ansma=0
ansmi=0
for i in range(n):
  if n-i-1>=k-1:
    ansma+=cmb(n-i-1,k-1,mod)*a[n-i-1]
    ansmi+=cmb(n-i-1,k-1,mod)*a[i]
print((ansma-ansmi)%mod)

Measured memory_bytes: 26740
def make_divisors(n):
    a,b =[],[]
    i = 1
    while i*i<=n:
        if n%i == 0:
            a.append(i)
            if i != n//i:
                b.append(n//i)
        i+= 1
    return a+b[::-1]

n = int(input())
c = 0
for i in range(1,n+1):
    if len(make_divisors(i))== 8 and i%2==1:
        c+=1
print(c)

Measured memory_bytes: 64388
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pii pair<int,int>
using namespace std;
void boost(){
 ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int n,ans,v[100],c[100];
main(){
boost();
cin>>n;
for(int k=1;k<=n;k++)
    cin>>v[k];
for(int i=1;i<=n;i++)
    cin>>c[i];
for(int k=1;k<=n;k++){
    if(v[k]>c[k])
        ans+=(v[k]-c[k]);
}
cout<<ans;
return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  
  if (A == B) {
    cout << "Draw" << endl;
  }
  else if (A == 1) {
    cout << "Alice" << endl;
  }
  else if (B == 1) {
    cout << "Bob" << endl;
  }
  else if (A > B) {
    cout << "Alice" << endl;
  }
  else {
    cout << "Bob" << endl;
  }
}

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

int main(void){
   
  int n;
  string s;
  cin >> n;
  map<string,int> mp{};
  
  for(int i=0;i<n;i++){
      cin >> s;
      mp[s] = 1;
  }
  cout << mp.size() << endl;
}


Measured memory_bytes: 19048
import scala.io.StdIn.{readInt, readLine};
object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt;
        val list = new DoublyLinkedList();
        for (i <- (0 until n)) {
            val input = readLine.split(" ");
            if (input(0) == "insert") {
                list.insert(input(1).toLong);
            } else if (input(0) == "delete") {
                list.delete(input(1).toLong);
            } else if (input(0) == "deleteFirst") {
                list.deleteFirst;
            } else {
                list.deleteLast;
            }
        }
        println(list);
    }
}
class DoublyLinkedList() {
    case class Node(key: Long, var prev: Node, var next: Node);
    private val head = Node(-1L, null, null);
    def isEmpty: Boolean = head.next == null && head.prev == null;
    override def toString: String = {
        def go(node: Node, ret: List[Long]): List[Long] =  if (node.key == -1L) ret else go(node.prev, node.key :: ret);
        if (isEmpty) "" else go(head.prev, Nil).mkString(" ");
    }
    def insert(key: Long): Unit = {
        if (isEmpty) {
            val node = Node(key, head, head);
            head.next = node;
            head.prev = node;
        } else {
            val node = Node(key, head, head.next);
            head.next.prev = node;
            head.next = node;
        }
    }
    
    private def _delete(node: Node): Unit = {
        val prev = node.prev;
        val next = node.next;
        if (prev == head && next == head) {
            head.next = null;
            head.prev = null;
        } else {
            prev.next = next;
            next.prev = prev;
        }
    }
    
    private def find(node: Node, key: Long): Node = node.key match {
        case -1L => null;
        case `key` => node;
        case _ => find(node.next, key);
    }
    
    def delete(key: Long): Unit = {
        val target = find(head.next, key);
        if (target != null) _delete(target);
    }
    
    def deleteFirst: Unit = {
        _delete(head.next);
    }
    def deleteLast: Unit = {
        _delete(head.prev);
    }
}


Measured memory_bytes: 467524
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int N;
  ll A[SIZE], B[SIZE];

  scanf("%d", &N);

  for(int i=0; i<N; i++) {
    scanf("%lld", A+i);
  }

  for(int i=0; i<N; i++) {
    scanf("%lld", B+i);
  }

  queue<int> que;
  bool ok[SIZE] = {};

  for(int i=0; i<N; i++) {
    int a = B[(i+N-1)%N];
    int b = B[(i+1)%N];

    if(B[i] >= A[i] + a + b) {
      que.push(i);
      ok[i] = true;
    }
  }

  ll counter = 0;
  while(que.size()) {
    int i = que.front(); que.pop();
    ll &a = B[(i+N-2)%N];
    ll &b = B[(i+N-1)%N];
    ll &c = B[i];
    ll &d = B[(i+1)%N];
    ll &e = B[(i+2)%N];

    assert(B[i] > A[i]);
    int t = (B[i] - A[i]) / (d + b);
    counter += t;
    B[i] -= t * (d + b);
    ok[i] = false;

    if (c >= A[i] + b + d && !ok[i]) {
      que.push(i);
      ok[i] = true;
      assert(0);
    }

    if (b >= A[(i+N-1)%N] + a + c && !ok[(i+N-1)%N]) {
      que.push((i+N-1)%N);
      ok[(i+N-1)%N] = true;
    }

    if (d >= A[(i+1)%N] + c + e && !ok[(i+1)%N]) {
      que.push((i+1)%N);
      ok[(i+1)%N] = true;
    }
  }


  bool f = true;
  for(int i=0; i<N; i++) {
    f &= A[i] == B[i];
  }

  if(f)
    printf("%lld\n", counter);
  else
    puts("-1");

  return 0;
}


Measured memory_bytes: 3968
#include <stdio.h>

int main(void){
  int N;
  int a, b, c;
  
  scanf("%d", &N);
  
  a = N / 100;
  b = (N - 100*a) / 10;
  c = N - 100*a - 10*b;
 
  if(a == c) printf("Yes\n");
  else printf("No\n");
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}


int main() {
  int N;
  cin>>N;
  vector<int64_t>A(N),table(N);
  int64_t sum=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end());
  for(int i=0;i<N;i++){
    sum+=A[i];
    table[i]=sum;
  }
  A.push_back(A[N-1]);
  int MAX=-1;
  for(int i=0;i<N;i++){
    if(table[i]*2<A[i+1]){MAX=i;}
  }
  cout<<N-1-MAX<<endl;
  return 0;
}

Measured memory_bytes: 5620
import copy

def bubbleSort(A):
    flag = 1
    while flag:
        flag = 0
        for j in range(len(A)-1,0,-1):#こういう書き方なんや……逆順処理
            if int(A[j][1]) < int(A[j-1][1]):
                A[j],A[j-1] = A[j-1],A[j]
                flag += 1
    return A

def selectionSort(A):
    for i in range(len(A)):
        minj = i
        for j in range(i,len(A)):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        if i != minj:
            A[i],A[minj] = A[minj],A[i]
    return A

N = int(input())
lst1 = list(input().split())
lst2 =  copy.copy(lst1)
print(" ".join(bubbleSort(lst1)))
print("Stable")
print(" ".join(selectionSort(lst2)))
if lst1 == lst2:
    print("Stable")
else:
    print("Not stable")


Measured memory_bytes: 6344
import sys


def solve(n, m, arr):
    odds = []
    evens = []
    for a in arr:
        if a % 2 == 0:
            evens.append(a)
        else:
            odds.append(a)

    if len(odds) > 2:
        print('Impossible')
        return

    if len(odds) == 2:
        o1, o2 = odds
        aaa = [o1] + evens + [o2]
        bbb = [2] * (o1 // 2 + 1)
        bbb += evens
        bbb += [2] * (o2 // 2)

    elif len(odds) == 1:
        if odds[0] == 1:
            aaa = odds + evens
            bbb = evens + odds
        elif evens:
            aaa = odds + evens
            bbb = [odds[0] - 1] + evens[:-1] + [evens[-1] + 1]
        else:
            aaa = odds
            bbb = [odds[0] // 2, odds[0] // 2 + 1]

    else:
        aaa = evens
        bbb = [1] + evens[:-1] + [evens[-1] - 1]

    print(*aaa)
    print(len(bbb))
    print(*bbb)


n, m, *aaa = map(int, sys.stdin.buffer.read().split())
solve(n, m, aaa)


Measured memory_bytes: 4980
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
int p[100001],b[100001];
int main(){
	int n,ans=0;
	cin>>n;
	p[0]=-1;
	REP(i,1,n+1){
		cin>>p[i];
	}
	REP(i,1,n+1){
		if(p[i]==i){
			swap(p[i],p[i+1]);
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
	
}


Measured memory_bytes: 640
using System;

public class AtCoder
{
    public static void Main()
    {
        string s;
        s = Console.ReadLine().Trim();
        int[] a = new int[s.Length];
        string t = "";
        long w = 0;
        for (int i = 0; i < s.Length; i++)
        {
            t = s.Substring(i, 1);
            if (t == "B") a[i] = 0;
            else
            {
                a[i] = 1;
                w++;
            }
        }
        long x = w * (w + 1) / 2;
        long y = 0;
        long ans = 0;

        for (long i = 0; i < s.Length; i++)
        {
            if(a[i] == 1)
            {
                y += i + 1;
            }
        }
        ans = y - x;



        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 17308
N, K = list(map(int, input().split()))
As = list(map(int, input().split()))

def compute(city, K):
    for i in range(K):
        # 3-1番目=2
        city = As[city-1]
    print(city)

cities_visited = [False] * N
i = 0
city = 1
city_visited_time = {}
# city_visited_timeの出力結果例2
# リストの05142の順番
# {0: 0, 5: 1, 1: 2, 4: 3, 2: 4}
# ループの計算
# 最初1-1のリスト0の　3 6からスタート
while not cities_visited[city - 1]:
    cities_visited[city - 1] = True
    city_visited_time[city-1] = i
    # 次の街はリストasリスト[6-1]の5=2から
    city = As[city-1]
    i += 1
    # cityの出力結果3,4,1 6,2,5,3,2渦巻型
    # iの出力結果合計3回　5回 
loop_start = city_visited_time[city-1]
# loop_startの出力結果0 2
loop_end = i
# 出力結果i同様3 5

div = (K - loop_start) // (loop_end - loop_start)
# div出力結果242400738057749783
if K - loop_start < 0 or div == 0:
    compute(1, K)
else:
    compute(city, K - loop_start - div * (loop_end - loop_start))
    

Measured memory_bytes: 45828
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

int main() {
	string s; int w;
	cin >> s >> w;
	int n = s.length();
	for (int i = 0; i < n; i += w) {
		cout << s[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

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

  for (int i = X - K + 1; i <= X + K - 1; i++)
  {
    cout << i;
    if (i == X + K - 1)
      cout << endl;
    else
      cout << " ";
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

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

	int H, W, N;
	cin >> H >> W >> N;
	int a = max( H, W );
	cout << (N+a-1) / a << endl;

	return 0;
}


Measured memory_bytes: 256
#if 1

#include<bits/stdc++.h>
using namespace std;
long long a[3001];
long long d[3001];
int main()
{
	long long n;
	cin >> n;
	for(int i = 1;i <= n;i++)
    {
        scanf("%lld",&a[i]);
    }
	for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j+i-1 <= n;j++)
        {
            d[j] = max(a[j]-d[j+1],a[j+i-1]-d[j]);
        }
    }
	cout << d[1];
}

#endif // 1++

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

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

int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  // 
  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  string s;cin>>s;
  int b[26]={};
  int s_long=s.size();
  char ans;
  REP(i,s_long){
    int num=s[i]-97;
    b[num]=1;
  }
  // REP(i,26)P(b[i]);
  REP(i,26){
    if(i==25 && b[i]==1){
      P("None");
      break;
    }
    if(b[i]==0){
      ans=(char)(i+97);
      P(ans);
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 1,0 },{ 0,1 }
};

signed main() {
	multiset<string> strs;

	int n, l;
	scnaf("%d %d", &n, &l);
	REP(i, n) {
		char str[10000];
		scnaf("%s", str);
		string s(str);
		strs.insert(s);
	}
	for (auto itr : strs) {
	pritnf("%s", itr.c_str());

	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
X=int(input())

a=0
count=0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            a=500*i+100*j+50*k
            if a==X:
                count+=1
                
                
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B;
    bool h = false;
    cin >> A >> B;

    for (int i=0; i<1000000000; i++){
        if(abs(A-i) == abs(B-i)){
            cout << i << endl;
            h = true;
            break;
        }
    }

    if(h == false){
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, sum = 0;
  vector<string> s(3);
  vector<int> cnt(3, 0);
  cin >> n >> s[0] >> s[1] >> s[2];
  for (int i = 0; i < n;i++){
    cnt[0] = cnt[1] = cnt[2] = 0;
    for (int j = 0; j < 3;j++){
      for (int k = 0; k < 3;k++){
        if(j==k){
          cnt[j]++;
          continue;
        }
        if(s[j][i]==s[k][i]){
          cnt[j]++;
        }
      }
    }
    sum += 3 - max(cnt[0], max(cnt[1], cnt[2]));
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3604
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    ll X;
    in(X);

    ll MIN = -1000;
    ll MAX = 1000;
    for (ll i=MIN; i<MAX-1; i++) {
        for (ll j=i+1; j<MAX; j++) {
            ll i5 = i*i*i*i*i;
            ll j5 = j*j*j*j*j;
            if (i5 - j5 == X) {
                out(i << ' ' << j);
                exit(0);
            }
            else if (i5 + j5 == X) {
                out(i << ' ' << -j);
                exit(0);
            }
            else if (i5 - j5 == -X) {
                out(-i << ' ' << -j);
                exit(0);
            }
            else if (i5 + j5 == -X) {
                out(-i << ' ' << j);
                exit(0);
            }
        }
    }

	return 0;
}


Measured memory_bytes: 3588
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C: Time Gap
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int T = 24;
const int H = T / 2;

/* typedef */

/* global variables */

int dns[H + 1], ds[H];
bool used[T];

/* subroutines */

inline void setmin(int &a, int b) { if (a > b) a = b; }

int check() {
  int mindf = T, prvi = 0;
  for (int i = 1; i < T; i++)
    if (used[i]) {
      setmin(mindf, i - prvi);
      prvi = i;
    }
  setmin(mindf, T - prvi);
  return mindf;
}

int rec(int m, int u) {
  if (u >= m) return check();

  used[ds[u]] = true;
  int r0 = rec(m, u + 1);
  used[ds[u]] = false;

  used[T - ds[u]] = true;
  int r1 = rec(m, u + 1);
  used[T - ds[u]] = false;

  return max(r0, r1);
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    int di;
    scanf("%d", &di);
    dns[di]++;
  }
  dns[0]++;

  if (dns[0] > 1 || dns[H] > 1) {
    puts("0");
    return 0;
  }

  used[0] = true;
  if (dns[H] == 1) used[H] = true;

  int m = 0;
  for (int d = 1; d < H; d++)
    switch (dns[d]) {
    case 0: break;
    case 1: ds[m++] = d; break;
    case 2: used[d] = used[T - d] = true; break;
    default: puts("0"); return 0;
    }

  int r = rec(m, 0);
  printf("%d\n", r);
  return 0;
}


Measured memory_bytes: 256
// Last Change: 01/25/2020 15:58:34.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  char ipt;
  cin >> ipt;
  cout << static_cast<char>(ipt + 1) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100000

int main(void) {

    int i, j, k;
    int n, H[N], W[N];

    for (i = 0; i < N; i++) {
        H[i] = 0;
        W[i] = 0;
    }

    i = 0;
    while (1) {
        scanf("%d%d", &H[i], &W[i]);
        if ((H[i] == 0) && (W[i] == 0)) {
            break;
        }
        i++;
    }
    n = i;

    for (i = 0; i < n; i++) {
        for (j = 1; j <= H[i]; j++) {
            for (k = 1; k <= W[i]; k++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;

}

Measured memory_bytes: 1352
// https://atcoder.jp/contests/abc118/tasks/abc118_c

// http://ctylim.hatenablog.com/entry/2015/08/30/191553
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cstdio>

#define ALL(a) (a).begin(), (a).end()
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define MAXINDEX(c) distance((c).begin(), max_element((c).begin(), (c).end()))
#define MININDEX(c) distance((c).begin(), min_element((c).begin(), (c).end()))
#define DEBUG(x) std::cerr << #x << " = " << (x) << " (" << __FILE__ << "::" << __LINE__ << ")" << std::endl;
#define ERROR(s) std::cerr << "Error::" << __FILE__ << "::" << __LINE__ << "::" << __FUNCTION__ << "::" << (s) << std::endl;
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)

#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

int inputValue()
{
  int a;
  // std::cin >> a;
  scanf("%d", &a);
  return a;
}

void inputArray(int *p, int a)
{
  rep(i, a)
  {
    // std::cin >> p[i];
    scanf("%d",p+i);
  }
}

void inputVector(std::vector<int> *p, int a)
{
  rep(i, a)
  {
    int input;
    // std::cin >> input;
    scanf("%d", &input);
    p->push_back(input);
  }
}

template <typename T>
void output(T a, int precision)
{
  if (precision > 0)
  {
    std::cout << std::setprecision(precision) << a << "\n";
  }
  else
  {
    std::cout << a << "\n";
  }
}

using namespace std;

int gcd(int a, int b)
{
  while (1)
  {
    if (a < b)
      swap(a, b);
    if (!b)
      break;
    a %= b;
  }
  return a;
}

int main(int argc, char **argv)
{

  int N = inputValue();
  vector<int> v;
  inputVector(&v, N);

  int sum = 0;
  EACH(k, v)
  {
    sum += (*k-1);
  }

  cout << sum << endl;
  return 0;
}

//

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	string N;
	cin >> N;
	int ans = 0;
	bool plus = false;
	for (int i = N.size()-1; i >= 0; i--)
	{
		int a = N[i] - '0';
		if (plus)
			a++;
		if (a == 10)
			plus = true;
		if (a == 5)
		{
			if (i > 0 && N[i-1] > '4')
				plus = true;
			else
				plus = false;
			ans += 5;
		}
		else if (a < 6)
		{
			ans += a;
			plus = false;
		}
		else
		{
			ans += 10 - a;
			plus = true;
		}
	}
	if (plus)
		ans++;
	cout << ans << endl;
}



Measured memory_bytes: 1412
#include <stdio.h>

int max(int a, int b){
	return a>b?a:b;
}

int min(int a, int b){
	return a<b?a:b;
}

int main(){
	
	int i,n;
	scanf("%d",&n);
	int r[n],minv,maxv=-1000000000;
	for(i=0;i<n;i++){
		scanf("%d",&r[i]);
    }

	minv = r[0];
	for(i=1;i<n;i++){
		maxv = max(maxv, r[i]-minv);
		minv = min(minv, r[i]);
	}
	printf("%d\n", maxv);

	return 0;
}

Measured memory_bytes: 2580
a = int(input())
b =list(map(int,input().split()))

c = 0

for i in range(a):
  if i>0:
    if (b[i] - b[i-1])<-1:
      c+=2
    if (b[i] - b[i-1])==-1:
      c+=1
    if (b[i] - b[i-1])>0:
      c=0
  if c>=2: break
if c<=1: print("Yes")
else: print("No")

Measured memory_bytes: 14396
#include <iostream>
#include <string>
using namespace std;
int main(){
	//freopen("test", "r", stdin);
	ios::sync_with_stdio(false);
	string str;
	cin >> str;
	int ans = 0;
	for(int i = 0; i < str.size() / 2; ++i){
		if(str[i] != str[str.size() - 1 - i]){
			++ans;	
		}	
	}
	cout << ans << '\n';
	return 0;
}


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

int main() {
    int n, m, a, b;
    cin >> n >> m;
    int branch[50][50] = {0};
    for(int i=0; i<m; i++) {
        cin >> a >> b;
        branch[a-1][b-1]=1;
        branch[b-1][a-1]=1;
    }

    int cnt=0;
    for(int i=0; i<n; i++) {
        for(int j=i+1; j<n; j++) {
            if(branch[i][j]==0) continue;

            branch[i][j]=0; branch[j][i]=0;

            //sousaku
            int visited[n]={0};
            visited[0]=1;

            queue<int> q;
            q.push(0);

            while(!q.empty()) {
                int v=q.front();
                q.pop();

                for(int i=0; i<n; i++) {
                    if(branch[i][v]==1) {
                        if(!visited[i]) {
                            q.push(i);
                            visited[i]=1;
                        }
                    }
                }
            }

            bool all_visited=true;
            for(int i=0; i<n; i++) if(!visited[i]) all_visited=false;
            if(!all_visited) cnt++;

            branch[i][j]=1; branch[j][i]=1;
        }
    }

    cout << cnt << endl;

    return 0;
}


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

using namespace std;

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

	int n = s.size();

	bool ok = true;
	for (int i = 0; i < n; i++) {
		if (s[i] != s[n - 1 - i]) {
			ok = false;
			break;
		}
	}
	// cout << ok << endl;

	string t = s.substr(0, (n - 1) / 2);
	string u = s.substr((n + 3) / 2 - 1);
	// cout << t << endl;
	// cout << u << endl;
	for (int i = 0; i < t.size(); i++) {
		if (t[i] != t[t.size() - 1 - i]) {
			ok = false;
			break;
		}
	}
	// cout << ok << endl;

	for (int i = 0; i < u.size(); i++) {
		if (u[i] != u[u.size() - 1 - i]) {
			ok = false;
			break;
		}
	}
	// cout << ok << endl;

	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <cstring>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front

using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

typedef pair<int, int> P;

bool ps1(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first昇順
    return forall_a_in_P.first < forall_b_in_P.first;
}
bool ps2(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first降順
    return forall_a_in_P.first > forall_b_in_P.first;
}
bool ps3(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second昇順
    return forall_a_in_P.second < forall_b_in_P.second;
}
bool ps4(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second降順
    return forall_a_in_P.second > forall_b_in_P.second;
}


int main()
{
    int n,k;
    cin>>n>>k;
    vector<int>h(n);
    rep(i,n)cin>>h[i];
    sort(all(h),greater<int>());
    ll sum=0;
    FOR(i,k,n){
        sum+=h[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define MAX_V 1000
int V,cmp[MAX_V];
vector<int> G[MAX_V],rG[MAX_V],vs,a,xx;
int used[MAX_V];
bool mm[1000];
void addedge(int from,int to){
  G[from].push_back(to);
  rG[to].push_back(from);
} 
void dfs(int v){
  used[v]=1;
  for(int i=0;i<G[v].size();i++)
    if(!used[G[v][i]])dfs(G[v][i]);
  vs.push_back(v);
}
void rdfs(int v,int k){
  used[v]=1;
  cmp[v]=k;
  for(int i=0;i<rG[v].size();i++){
    if(!used[rG[v][i]])rdfs(rG[v][i],k);
  }
}
void dfs2(int v,int k){
  mm[v]=1;
  used[v]=k;
  for(int i=0;i<G[v].size();i++)
    if(!mm[G[v][i]])dfs2(G[v][i],k);
  xx.push_back(v);
}
int scc(){
  int pp=0;
  memset(used,0,sizeof(used));
  vs.clear();
  for(int v=0;v<V;v++)
    if(!used[v])dfs(v);
  memset(used,0,sizeof(used));
  int k=1;
  for(int i=vs.size()-1;i>=0;i--)
    if(!used[vs[i]]){
      rdfs(vs[i],k++);
    }
  k=1;
  map<int,int>m;
  memset(used,0,sizeof(used));
  r(i,V){
    if(!used[i]){
      memset(mm,0,sizeof(mm));
      dfs2(i,k);
      r(j,xx.size())if(1){
        m[xx[j]]=0;
      }
      xx.clear();
      m[i]=cmp[i];
      k++;
    }
  }
  r(i,V)if(m[i])
    a.push_back(m[i]);
  return k;
}
int main(){
  int x,y;
  while(cin>>V,V){
    double d[V],ans=0;
    a.clear();
    r(i,1000)G[i].clear(),rG[i].clear();
    r(i,V){
      cin>>d[i]>>x;
      r(j,x){
        cin>>y;
        addedge(i,y-1);
      }
    }
    scc();
    int cnt=0;
    r(i,a.size()){
      double p=0;
      int c=0;
      r(j,V)if(cmp[j]==a[i]){
        if(!c++)p+=d[j];
        else p*=d[j];
      }
      if(!cnt++)ans+=(1.0-p);
      else ans*=(1.0-p);
    }
    printf("%.9f\n",ans);
  }
}

Measured memory_bytes: 3452
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] c = new int[n];
		int[] s = new int[n];
		int[] f = new int[n];
		
		for (int i = 0; i < n - 1; i++) {
			c[i] = sc.nextInt();
			s[i] = sc.nextInt();
			f[i] = sc.nextInt();
		}
		
		for (int i = 1; i <= n ; i++) {
			int j = i;
			int t = 0;
			while (j != n) {
				if (s[j - 1] <= t && t % f[j - 1] == 0) {
					t += c[j - 1];
					j++;
				} else {
					t++;
				}
			}
			System.out.println(t);
		}
	}
}

Measured memory_bytes: 26016
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

N = int(input())
A = list(map(int, input().split()))

L = [0] * N
R = [0] * N

L[0] = A[0]
R[N-1] = A[-1]

for n in range(1, N):
    L[n] = gcd(L[n - 1], A[n])
for n in reversed(range(N-1)):
    R[n] = gcd(R[n + 1], A[n])

ans = 0
for n in range(N):
    if n == 0:
        ans = max(ans, R[n+1])
    elif n == N - 1:
        ans = max(ans, L[n-1])
    else:
        ans = max(ans, gcd(L[n-1], R[n+1]))

print(ans)


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

int dig_num(int n){return ( n<10? n: dig_num(n/10)+n%10) ; }

int main(){
  int N; cin >> N;
  int m = 100;
  int a,b;
  for(int i=1;i<N;i++){
    a = dig_num(N-i);
    if(a<m){
	  b = dig_num(i);
      m = min(a+b,m);
    }
  }
  
  cout << m << "\n";
}

Measured memory_bytes: 636
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
long long a[3];
int main(){
    scanf("%lld %lld %lld", a, a+1, a+2);
    sort(a, a+3);
    if(a[2]%2==0 || a[1]%2==0 || a[0]%2==0)
        printf("0\n");
    else 
        printf("%lld\n",a[0]*a[1]);
    //system("pause");
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll dp[101010][4];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	cin>>x;
	memset(dp,0xcf,sizeof(dp));
	dp[0][0]=x;
	FOR(i,N-1) {
		cin>>s>>x;
		
		if(s=="+") {
			dp[i+1][3] = dp[i][3]-x;
			dp[i+1][2] = max(dp[i+1][3], dp[i][2]+x);
			dp[i+1][1] = max(dp[i+1][2], dp[i][1]-x);
			dp[i+1][0] = max(dp[i+1][1], dp[i][0]+x);
		}
		if(s=="-") {
			ll T[4];
			
			T[0]=dp[i][1];
			T[1]=max(dp[i][0],dp[i][2]);
			T[2]=max(dp[i][1],dp[i][3]);
			T[3]=dp[i][2];
			dp[i+1][3] = T[3]-x;
			dp[i+1][2] = max(dp[i+1][3], T[2]+x);
			dp[i+1][1] = max(dp[i+1][2], T[1]-x);
			dp[i+1][0] = max(dp[i+1][1], T[0]+x);
		}
		
	}
	
	cout<<*max_element(dp[N-1],dp[N-1]+4)<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

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

    vector<int> v(26);
    for (int i = 0; i < w.length(); i++){
        v[w[i] - 'a']++;        
    }

    bool flag = true;
    for (int i = 0; i < 26; i++){
        if(v[i] % 2 != 0) flag = false;        
    }
    if(flag == true) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
class DisjointSet():
    def __init__(self, n):
        self._p = [x for x in range(n)]
        self._size = [-1 for x in range(n)]
        self._rank = [0 for x in range(n)]
    
    def find(self, p):
        if self._p[p] != p:
            self._p[p] = self.find(self._p[p])
        return self._p[p]

    def union(self, p, q):
        pp, qq = self.find(p), self.find(q)
        if pp != qq:
            if self._rank[pp] > self._rank[qq]:
                self._p[qq] = pp
                self._rank[pp] += 1
                self._size[pp] += self._size[qq]
            else:
                self._p[pp] = qq
                self._rank[qq] += 1
                self._size[qq] += self._size[pp]
    
    def size(self, p):
        return self._size[self.find(p)]


n, m = [int(x) for x in input().split()]
b =  [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
b.reverse()
r = []
t = n*(n-1)//2
ds = DisjointSet(n)
for q, p in b:
  r.append(t)
  qq, pp = ds.find(p), ds.find(q)
  if pp != qq:
    t -= ds.size(pp) * ds.size(qq)
  ds.union(p, q)
for x in reversed(r):
  print(x)

Measured memory_bytes: 25208
#include<stdio.h>

int main(){

   int H, W;
   int i, j;

   scanf("%d %d", &H, &W);

   while(H!=0 || W!=0){
      for(i=0;i<H;i++){
         if(i==0 || i==H-1){
            for(j=0;j<W;j++) printf("#");
         }else{
            for(j=0;j<W;j++){
               if(j==0 || j==W-1) printf("#");
               else printf(".");
            }
         }
         printf("\n");
      }
      printf("\n");
      scanf("%d %d", &H, &W);
   }

   return 0;

}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
int main(void){
   int h,w;
   cin >> h >> w;
   string c[h];
   for(int i=0;i<h;i++){
       cin >> c[i];
   }
   for(int i=0;i<h;i++){
       cout << c[i] << endl;
       cout << c[i] << endl;
   }
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
	string s, x;
	cin >> s;
	cin >> x;
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != x[i])
		{
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3912
#include<iostream>
using namespace std;
int main() {
    int table[5] = {0};
    for (int i = 0; i < 3; ++i) {
        int a, b; cin >> a >> b;
        table[a]++;
        table[b]++;
    }
    int cnt = 0, cnt2 = 0;
    for (int i = 1; i <= 4; ++i) {
        if (table[i] == 1) {
            cnt++;
        } else if (table[i] == 2) {
            cnt2++;
        }
    }
    if (cnt == 2 && cnt2 == 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = 0;

        if ((a + b) >= (a - b) && (a + b) >= (a * b)) {
            ans = a + b;
        } else if ((a - b) >= (a + b) && (a - b) >= (a * b)) {
            ans = a - b;
        } else {
            ans = a * b;
        }


        System.out.println(ans);

        sc.close();
    }    
}


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

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		double D = in.nextDouble();
		double T = in.nextDouble();
		double S = in.nextDouble();
		
		if(D / S > T) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}
	}
}


Measured memory_bytes: 37260
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int a[5] ;
    int count = 0 ;
    for(int i = 0 ; i < 5 ;i++){
        cin >> a[i] ;
        if(a[i] == 0){
            count= i+1 ;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3584
import java.util.*;
import java.lang.*;

import static java.lang.StrictMath.abs;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[3];
        for(int i=0; i<3; i++){
            a[i] = sc.nextInt();
        }
        int d = sc.nextInt();


        if(abs(a[2]-a[0]) <=d || (abs(a[0] - a[1])<=d && abs(a[1] - a[2])<d)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }



        }

    }

Measured memory_bytes: 21716