akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(){
  int N,K,i,t,r;

  cin>>N>>K;

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

    if(t<(K-t)){
      r+=t*2;
    }else{
      r+=(K-t)*2;
    }
  }
  cout<<r<<endl;

}


Measured memory_bytes: 256
A=input()
B=input()
C=input()
D=[]
E=[]
F=[]
s="a"
x=len(A)
y=len(B)
z=len(C)
for i in range(len(A)):
    D.append(A[i])
for i in range(len(B)):
    E.append(B[i]) 
for i in range(len(C)):
    F.append(C[i])
while x>=0 and y>=0 and z>=0:
    if s=="a":
        if x==0:
            print("A")
            break
        else:
            s=(D[0])
            D.pop(0)
            x-=1
    elif s=="b":
        if y==0:
            print("B")
            break
        else:
            s=E[0]
            E.pop(0)
            y-=1
    elif s=="c":
        if z==0:
            print("C")
            break
        else:
            s=F[0]
            F.pop(0)
            z-=1

 
    

Measured memory_bytes: 3064
#include <iostream>
int digit(unsigned long long n){
	int d=1;
	while(n>9){
		n/=10;
		d++;
	}
	return d;
}
int main(){
  unsigned long long x,y;
  while(std::cin>>x>>y){
	 std::cout<<digit(x+y)<<"\n";
  }
  return 0;
}

Measured memory_bytes: 1152
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES
#define ll long long
#define ins Not Needed Thing
#define ull unsigned long long
#define ld long double
#define Accepted 0
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define SORRY FUL Accepted 
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
#define Toktama Kazakhstan 

using namespace std;

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;                                          
const int PRI = 555557;
const int pri = 997;

int tests = 1;

int dp[N], n;

inline void Solve () {
	//easy
	cin >> n;
	for (int i = 0; i < n; i ++) {
		dp[i] = inf;
	}		

	for (int i = 1; i <= 9; i ++) {
		dp[i % n] = min(dp[i % n], i);
	}

	set < pair < int, int > > s;

	for (int i = 1; i <= 9; i ++) {
		s.insert(mp(dp[i % n], i));
	}

	while (s.size()) {
		auto v = *s.begin();
		s.erase(s.begin());

		for (int i = 0; i < 10; i ++) {
			int nxt = (v.S * 10 + i) % n;
			if (dp[nxt] > v.F + i) {
				dp[nxt] = v.F + i;
				s.insert(mp(dp[nxt], nxt));
			}
		}
	}

	cout << dp[0];
}

int main () {
	SpeedForce;
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);	
	// cin >> tests;
	while(tests --) {
		Solve ();
		// Ee Zadrot
	}

	return Accepted; 
}

Measured memory_bytes: 9600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeSet;

import javax.swing.*;

import static java.util.Arrays.binarySearch;
import static java.util.Arrays.copyOfRange;
import static java.util.Arrays.sort;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {

    private static int mod = 2019;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int x = 1, y = 1;
        long ans = 0;
        char[] s = in.next().toCharArray();
        Map<Integer, Integer> map = new HashMap<>();
        map.put(1, 1);
        for (int i = 0; i < s.length; i++) {
            x = x * 202 % mod;
            y = (y * 10 + (s[i] - '0')) % mod;
            //out.println(i + 1 + " " + y * x % mod);
            ans += map.getOrDefault(y * x % mod, 0);
            map.put(y * x % mod, map.getOrDefault(y * x % mod, 0) + 1);
        }
        out.println(ans);

    }



}

class InputReader {

    private final BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

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

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

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

}

Measured memory_bytes: 47832
#coding :utf-8

N,M,X=map(int,input().split())

C=[]
A=[]
for i in range(N):
  t=list(map(int,input().split()))
  C.append(t[0])
  A.append(t[1:])
result=-1

for i in range(1<<N):
  t=[0]*M
  c=0
  for j in range(N):
    if ((i>>j) & 1==0):
      continue
    c+=C[j]
    for k in range(M):
      t[k]+=A[j][k]
    
  
  if all(x>=X for x in t):
    if result==-1:
      result=c
    else:
      result=min(result,c)

print(result)

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

int main(void){
    int n;
    std::cin >> n;
    std::vector<int> a(n), b(n), c(n-1);
    for(int i = 0; i < n; i++){
        std::cin >> a[i];
        --a[i];
    }
    for(int i = 0; i < n; i++){
        std::cin >> b[i];
    }
    for(int i = 0; i < n - 1; i++){
        std::cin >> c[i];
    }

    int bi = -1;
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += b[a[i]];
        if(a[i] - bi == 1) ans += c[bi];
        bi = a[i];
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
lli gcd(lli num1, lli num2){
    return num2 != 0 ? gcd(num2, num1 % num2) : num1;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,Z,W,H,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  K=N;
  Vec(P,lli,N,0);
  //rep(i,0,N)cin >> P[i];
  rep(i,0,K)rep(j,0,K)rep(k,0,K)sum+=gcd(i+1,gcd(j+1,k+1));
  Out(sum);
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void dfs(int cur, int pre, vector<int> &res, vector<ll> &dp, const vector<ll> &a, const Graph &G) {
    auto iter = lower_bound(dp.begin(), dp.end(), a.at(cur));
    ll tmp = *iter;
    *iter = a.at(cur);
    res.at(cur) = lower_bound(dp.begin(), dp.end(), LINF) - dp.begin();
    for (int nx : G.at(cur)) {
        if (nx != pre) dfs(nx, cur, res, dp, a, G);
    }
    *iter = tmp;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; ++i) cin >> a.at(i);
    Graph G(n);
    for (int i=0; i<n-1; ++i) {
        int a, b;
        cin >> a >> b;
        G.at(a-1).push_back(b-1);
        G.at(b-1).push_back(a-1);
    }

    vector<int> res(n);
    vector<ll> dp(n, LINF);
    dfs(0, -1, res, dp, a, G);
    for (int x : res) cout << x << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 35396
import java.util.*;
class Main{
public static void main(String[]args){
  Scanner sc=new Scanner(System.in);
  String s=sc.next();
  if(s.equals("SSS")){
  System.out.println(0);
  }
  if(s.equals("SSR")){
  System.out.println(1);
  }
  if(s.equals("SRS")){
  System.out.println(1);
  }
  if(s.equals("SRR")){
  System.out.println(2);
  }
  if(s.equals("RSS")){
  System.out.println(1);
  }
  if(s.equals("RSR")){
  System.out.println(1);
  }
  if(s.equals("RRS")){
  System.out.println(2);
  }
  if(s.equals("RRR")){
  System.out.println(3);
  }
}
}


Measured memory_bytes: 35608
#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define	pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigboi        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
#define SHUF(v) shuffle(all(v), RNG);
// Use mt19937_64 for 64 bit random numbers. 

int dp[1002][1002];
void solve(){	
	int n, m;
	cin>>n>>m;
	char mat[n][m];
	FOR(i, 0, n){
		FOR(j, 0, m){
			cin>>mat[i][j];
		}
	}
	FOR(i, 0, n){
		FOR(j, 0, m){
			if(i==0 && j==0){
				dp[i][j] = 1;
				continue;
			}
			else if(mat[i][j] == '#'){
				dp[i][j] = 0;
				continue;
			}
			if(i>0){
				dp[i][j] += dp[i-1][j];
			}
			if(j>0){
				dp[i][j] += dp[i][j-1];
			}
			dp[i][j]%=inf;
		}
	}
	cout<<dp[n-1][m-1];
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0); 	
	int t=1;
	//cin>>t;
	FOR(i, 1, t+1){	
		//cout<<"Case #"<<i<<": ";
		solve();
	}
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
 
}


Measured memory_bytes: 9088
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	string s[3]; for(int i = 0; i < 3 ; i++) cin >> s[i];
	int id[3] = {};
	int current = 0;
	while (1) {
		current = s[current][id[current]++] - 'a';
		if (id[current] >= s[current].size ()) {
			cout << char('A' + current) << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
        "fmt"
)

func solution(n int, a []int) int {
        var memo [1e5 + 2]int
        for _, num := range a {
                memo[num]++
                memo[num+1]++
                memo[num+2]++
        }
        out := 0
        for _, num := range memo {
                if num > 0 {
                        out = max(out, num)
                }
        }
        return out
}

func max(x, y int) int {
        if x > y {
                return x
        }
        return y
}

func main() {
        var n int
        fmt.Scan(&n)
        a := make([]int, n)
        for i := range a {
                fmt.Scan(&a[i])
        }
        fmt.Println(solution(n, a))
}

Measured memory_bytes: 7552
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int D = scn.nextInt();
		int DD = 2 * D + 1;
		System.out.println((N%DD == 0)?N/DD:N/DD+1);
	}

}

Measured memory_bytes: 23764
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstring;
typedef pair<int, int> pint;
typedef pair<pint, int> ppint;
typedef pair<int, pint> pintp;
typedef unsigned int uint;
typedef long long llint;
typedef unsigned long long int ullint;

//container util
//------------------------------------------
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find((v).begin(), (v).end(), i) != (v).end())
#define ERASE(v,i) (v).erase(remove((v).begin(),(v).end(),i),(v).end())
#define me (*this)

//repetition
//------------------------------------------
#define rep(i,s) for(int i=0; i<(int)(s); i++)

//constant
//--------------------------------------------
const int INF = 100000000;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLEAR(a) memset((a), 0 ,sizeof(a))

//debug
#define debug(x)  cerr << #x << " = " << (x) << endl

int main() {
	while(1) {
		static int n;
		cin >> n;
		if(!n)
			break;
		vint test;
		rep(i,n) {
			vint tmp;
			rep(j,5) {
				static int t;
				cin >> t;
				tmp.pb(t);
			}
			test.push_back(accumulate(all(tmp), 0));
		}
		printf("%d %d\n", *max_element(all(test)), *min_element(all(test)));
	}
	return 0;
}

Measured memory_bytes: 0
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    h,w=map(int,input().split())
    S=[input() for _ in range(w)]
    DP=[[0]*w for _ in range(h)]
    if S[0][0]=='#':
        DP[0][0]=1
    for j in range(1,w):
        if S[0][j-1]=='.' and S[0][j]=='#':
            DP[0][j]=DP[0][j-1]+1
        else:
            DP[0][j]=DP[0][j-1]
    for i in range(1,h):
        if S[i-1][0]=='.' and S[i][0]=='#':
            DP[i][0]=DP[i-1][0]+1
        else:
            DP[i][0]=DP[i-1][0]
        for j in range(1,w):
            if S[i-1][j]=='.' and S[i][j]=='#':
                d=DP[i-1][j]+1
            else:
                d=DP[i-1][j]
            if S[i][j-1]=='.' and S[i][j]=='#':
                r=DP[i][j-1]+1
            else:
                r=DP[i][j-1]
            DP[i][j]=min(d,r)
    print(DP[-1][-1])

if __name__=='__main__':
    main()

Measured memory_bytes: 42096
c = []
sum = 0
5.times do
    t = gets.chomp
    sum += t.to_i
    c << t[-1].to_i if t[-1] != '0'
end
if c.empty?
    puts sum
else
    c.delete_at(c.index(c.min))
    puts sum + c.length*10 - c.inject(:+)
end


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

int main(void) {
  set<int> st;
  int s;
  cin >> s;
  st.insert(s);
  for (int i = 0;; i++) {
    if (s % 2 == 0) {
      s = s / 2;
    } else {
      s = 3 * s + 1;
    }
    if (st.find(s) != st.end()) {
      cout << i + 2 << endl;
      break;
    }
    st.insert(s);
  }

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

typedef std::vector<int> vec;

inline bool power_of_2(int n) {
    return (n & (n - 1)) == 0;
}

inline int max_divisor(int n) {
    return n & -n;
}

int g(const vec& sequence) {
    int sum = 0;
    for (int i = 0; i < sequence.size(); i++) {
        sum += sequence[i];
    }

    vec table(sum + 1);
    std::fill(table.begin() + 1, table.end(), -1);
    table[0] = 0;

    sum = 0;
    for (int i = 0; i < sequence.size(); i++) {
        int x = sequence[i];
        for (int a = sum & -x; a >= 0; a -= x) {
            if (table[a] >= 0) {
                int b = a + x;
                table[b] = std::max(table[a] + 1, table[b]);
            }
        }
        sum += sequence[i];
    }

    int max = 0;
    for (int i = 1; i <= sum; i <<= 1) {
        max = std::max(max, table[i]);
    }
    return max;
}

vec extract(const vec& sequence, int k) {
    vec subsequence;
    int min = INT_MAX;
    for (int i = 0; i < sequence.size(); i++) {
        int x = sequence[i];
        std::div_t xk = std::div(x, k);
        if (xk.rem == 0 && power_of_2(xk.quot)) {
            subsequence.push_back(x);
            min = std::min(min, x);
        }
    }
    for (int i = 0; i < subsequence.size(); i++) {
        subsequence[i] /= min;
    }
    return subsequence;
}

void sort_and_uniq(vec& numbers) {
    std::sort(numbers.begin(), numbers.end());
    numbers.erase(std::unique(numbers.begin(), numbers.end()), numbers.end());
}

int f(const vec& sequence) {
    vec numbers;
    for (int i = 0; i < sequence.size(); i++) {
        int x = sequence[i];
        numbers.push_back(x / max_divisor(x));
    }
    sort_and_uniq(numbers);

    int max = 0;
    for (int i = 0; i < numbers.size(); i++) {
        int k = numbers[i];
        const vec& subsequence = extract(sequence, k);
        max = std::max(max, g(subsequence));
    }
    return max;
}

int main() {
    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) {
            break;
        }
        vec sequence(n);
        for (int i = 0; i < n; i++) {
            std::cin >> sequence[i];
        }
        std::cout << f(sequence) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<queue>
#include<map>
#include<set>

using namespace std;

int read()
{
    int ans=0,f=1;
    char c=getchar();
    while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return ans*f;
}

const int N=105;
char s[N];

int main()
{
    scanf("%s",s+1);
    for(int i=1;i<=strlen(s+1);++i)
        printf("x");
    return 0;
}

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359;
#define inf (1 << 21);
#define mod 1000000007;

int main() {
    int A, B; cin >> A >> B;
    cout << A * B << endl;
    return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		String str = sc.nextLine();
		int k = sc.nextInt();
		char[] c = str.toCharArray();
		for (int i = 0; i < c.length; i++) {
			if (c[i] == 'a')
				continue;
			int tmp='z'+1-c[i];
			if(tmp<=k){
				k-=tmp;
				c[i]='a';
			}
		}
		if(k!=0){
			k%=26;

			int end=str.length()-1;
			c[end]+=k;
			if(c[end]>'z') c[end]-=26;
		}

		System.out.println(String.valueOf(c));
	}
}


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

int main(){
  int k,t;
  cin >> k >> t;
  int maxa = 0;
  int tmp;
  for(int i = 0;i < t;i++){
    cin >> tmp;
    maxa = max(maxa,tmp);
  }

  if(t == 1){
    cout << k-1 << endl;
    return 0;
  }

  maxa -= (k-maxa+1);
  if(maxa > 0){
    cout << maxa << endl;
  }else{
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	ll a,b,c;
	cin >> a >> b >> c;
	if (a%2 == 0 || b%2 == 0 || c%2 == 0) cout << 0 << endl;
	else {
		cout << min(min(a*b,b*c),a*c) << endl;
	}
	return 0;
}

Measured memory_bytes: 384
import collections

n, m = map(int, input().split())
list_ac = set()
dic = collections.defaultdict(lambda:0)

ac = 0
wa = 0

for _ in range(m):
    p, s = input().split()
    if s == "WA" and p not in list_ac:
        dic[p] += 1
    elif s =="AC" and p not in list_ac:
        list_ac.add(p)
        ac += 1
        if p in dic:
            wa += dic[p]
            
print(ac, wa)

Measured memory_bytes: 20016
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int l,r,d;
  cin>>l>>r>>d;
  int ans=0;
  for(int i=l;i<=r;i++){
    if(i%d==0){
      ++ans;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

typedef long long ll;
const int maxn = 100010;
int n;
ll a[maxn];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
    }
    sort(a + 1, a + n + 1);
    int l = 1, r = n, ans;
    auto chk = [&](int x) {
        ll s = a[x];
        for (int i = 1; i <= n; i++) if (i ^ x) {
            if (a[i] > s * 2) return 0;
            s += a[i];
        }
        return 1;
    };
    while (l <= r) {
        int mid = (l + r) >> 1;
        chk(mid) ? r = (ans = mid) - 1 : l = mid + 1;
    }
    printf("%d\n", n - ans + 1);
    return 0;
}

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

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

int main() {
    int n, a, b;
    bool flagA, flagB;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    vector<int> v(n);

    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    for (int i = 1; i < n + 1; i++) v[i - 1] = i;

    int cnt = 0;
    do {
        flagA = true;
        flagB = true;
        rep(i, n) {
            if (p[i] != v[i]) flagA = false;
            if (q[i] != v[i]) flagB = false;
        }

        if (flagA) a = cnt;
        if (flagB) b = cnt;
        cnt++;
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(a - b) << endl;

    return 0;
}

Measured memory_bytes: 256
x,n=map(int, input().split())
p=list(map(int, input().split()))
koho=[]
abmi=1000
for a in range(101):
    koho.append(x-50+a)
for a in p:
    if a in koho:
        koho.remove(a)
for a in koho:
    ab=abs(a-x)
    if ab<abmi:
        abmi=ab
        ans=a
print(ans)

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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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;
}
///////////////////////////////////////////////
/*（๑•﹏•๑｀) */

int main() {
	int N,M;
	cin >> N >> M;
	vector<int> X(N);
	REP(i,N){
	    cin >> X[i];
	}

	sort(ALL(X));

	vector<int> pairnum(M);
	vector<int> count(M);

	int index = 0;
	REP(i,100001){
		int nownum = 0;
		int m = i % M;

		while(1){
			if (index >= N) break;
			if (X[index] == i){
				nownum++;
				index++;
				continue;
			}else{
				break;
			}
		}

		count[m] += nownum;
		pairnum[m] += nownum / 2;

	}

	ll ans = 0;

	ans += count[0] / 2;
	count[0] = count[0] % 2;

	if (M % 2 == 0){
		ans += count[M/2] / 2;
		count[M/2] = count[M/2] % 2;
	}

	FORq(i,1,M/2){
		if ((M % 2 == 0) and (i == M / 2)) break;
		//cout << "i = " << i << ", " << count[i] << ", " << count[M-i] << "\n";
		int pairmin = min(count[i],count[M-i]);
		ans += pairmin;
		count[i] -= pairmin;
		count[M-i] -= pairmin;
	}

	REP(i,M){
	    ans += min(count[i] , pairnum[i] * 2) / 2;
	}


	cout << ans << "\n";




}


Measured memory_bytes: 1408
#include<stdio.h>
int main()
{
	int a,b,k,i; 
	scanf("%d %d %d",&a,&b,&k);
	
	
	do{
		if(a%2==0)
		{
			i=a;
			a=a/2;
			b=i/2+b;
		}
		else 
		{
			a--;
			i=a;
			a=a/2;
			b=i/2+b;
		 }
		k--;
		if(k==0) break;
	if(b%2==0)
	{
		i=b;
		b=b/2;
		a=i/2+a;
	}
	else 
	{
		
			b--;
			i=b;
			b=b/2;
			a=i/2+a;
	 }
	 k--;
	 if(k==0) break;
	}
	while(k>0);
	printf("%d %d",a,b);
	return 0;
}



Measured memory_bytes: 128
//alignment library in C++11 (raw translate of Ruby version)
//only linear gap penalty is supported.
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <tuple>
using namespace std;
typedef vector<int> vi;
typedef tuple<int,int,int> tiii;
typedef vector<tiii> vtiii;
void alignment(string &x, string &y){
	vector<vi>a(x.length()+1,vi(y.length()+1));
	vector<vtiii>back(x.length()+1,vtiii(y.length()+1));
	string tx,ty;
	int i,j,k;
	for(i=1;i<a.size();i++){a[i][0]=a[i-1][0]-1;back[i][0]=make_tuple(i-1,0,0);}
	for(j=1;j<a[0].size();j++){a[0][j]=a[0][j-1]-1;back[0][j]=make_tuple(0,j-1,1);}
	for(i=1;i<a.size();i++){
		for(j=1;j<a[0].size();j++){
			vi Z{x[i-1]==y[j-1]?a[i-1][j-1]:(a[i-1][j-1]-1),a[i-1][j]-1,a[i][j-1]-1};
			vi::iterator z=max_element(Z.begin(),Z.end());
			a[i][j]=*z;
			switch(z-Z.begin()){
				case 0: back[i][j]=make_tuple(i-1,j-1,2);break;
				case 1: back[i][j]=make_tuple(i-1,j  ,0);break;
				case 2: back[i][j]=make_tuple(i  ,j-1,1);break;
			}
		}
	}
	cout<<-a[x.length()][y.length()]<<endl;
}
int main(){
	string s,t;
	cin>>s>>t;
	alignment(s,t);
}

Measured memory_bytes: 16836
S = input() #l桁の数字を文字列型で入力
l = len(S) # 文字列の長さ
n = l - 1 # 文字列の間の数
ans = 0
for bit in range(1 << n): # 0から((1をnだけ右シフトした数)-1)までのfor文
    s = S[0]
    for i in range(n):
        if (bit & (1 << i)):
            s += '+'
        s += S[i+1]
    ans += sum(map(int, s.split('+')))
print(ans)

Measured memory_bytes: 8976
<?php
    $line = trim(fgets(STDIN));
    $arr1 = str_split($line);
    $arr2 = $arr1;
    krsort($arr1);
    foreach ($arr1 as $key => $val) {
        $arr3[] = $val;
    }
    $cnt = 0;
    for ($i=0;$i<count($arr1);$i++){
        if($arr2[$i] != $arr3[$i]){
            $cnt++;
        }
    }
    echo $cnt/2;



Measured memory_bytes: 4728
n=int(input())
l=[['a1']]+[[] for _ in range(9)]
for i in range(9):
  for b in l[i]:
    t=b[-1]
    for p in range(int(t)):
      l[i+1].append(b[:-1]+chr(97+p)+t)
    l[i+1].append(b[:-1]+chr(97+int(t))+str(int(t)+1))
for i in l[n-1]:
  if len(i)==12:
    print(i[:-2])
  else:
    print(i[:-1])

Measured memory_bytes: 14564
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <vector>
#include <cmath>
#include <map>
#include <stack>
#include <algorithm>
typedef long long int ll;
using namespace std;
const int MAX=5000+10;
const double eps=1e-9;
const double PI=acos(-1.0);

int sgn(double x)
{
    if (fabs(x)<eps) {
        return 0;
    }
    if (x<0) {
        return -1;
    }
    else return 1;
}
struct point
{
    double x,y;
    point(){}
    point(double _x,double _y)
    {
        x=_x;y=_y;
    }
    point operator +(const point &b)const
    {
        return point(x+b.x,y+b.y);
    }
    point operator -(const point &b)const
    {
        return point(x-b.x,y-b.y);
    }
    double operator ^(const point &b)const
    {
        return x*b.y-y*b.x;
    }
    double operator *(const point &b)const
    {
        return x*b.x+y*b.y;
    }
    point operator *(const double k)const
    {
        point kk;kk.x=k*x;kk.y=k*y;return kk;
    }
    double len(void)
    {
        return sqrt(x*x+y*y);
    }
};
int main(){
    //freopen("/Users/mac/Desktop/C++?¨????/test/test.txt", "r", stdin);
    int q;
    point p1,p2,p0;
    scanf("%lf%lf%lf%lf",&p0.x,&p0.y,&p1.x,&p1.y);
    scanf("%d",&q);
    while(q--){
        scanf("%lf%lf",&p2.x,&p2.y);
        point p01=p1-p0;
        point p02=p2-p0;
        if (sgn(p01^p02)==1) {
            printf("COUNTER_CLOCKWISE\n");
        }
        else if (sgn(p01^p02)==-1){
            printf("CLOCKWISE\n");
        }
        else{
            if (sgn(p01*p02)==-1) {
                printf("ONLINE_BACK\n");
            }
            else if (p01.len()<p02.len()) {
                printf("ONLINE_FRONT\n");
            }
            else{
                printf("ON_SEGMENT\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3248
n  = int(input())
li = list(map(int, input().split()))

cnt = 0

def all_not_equals(i, j, k):
    return li[i] != li[j] and li[j] != li[k] and li[k] != li[i]

def could_be_triangle(i, j, k):
    e = max(li[i], li[j], li[k])

    return ((li[i] + li[j] + li[k]) - e) > e

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            if all_not_equals(i, j, k) and could_be_triangle(i, j, k):
                # print(i + 1, j + 1, k + 1)
                cnt += 1

print(cnt)

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

using namespace std;
typedef long long ll;

int main() {
  int q;
  cin >> q;
  
  ll n = 1e5+10;
  ll m = sqrt(n) + 1;
  vector<bool> v(n, true);
  vector<int> primes;
  v[1] = false;
  for (ll i = 2; i < m; i++) {
    if (!v[i]) continue;
    primes.push_back(i);
    for (ll j = i + i; j < n; j += i) 
      v[j] = false;
  }
  for (ll i = m; i < n ; i++)
    if (v[i]) primes.push_back(i);
  vector<int> pref(n+1, 0);
  for (int i = 1; i <= n; i++) {
    pref[i] = pref[i-1];
    if (i%2 == 1 and v[i] and v[(i+1)/2]) pref[i]++;
  }
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << pref[r] - pref[l-1] << "\n";
  }
  return 0;
}



Measured memory_bytes: 1152
n = int(input())
a = list(map(int, input().split()))

cnt = [0] * ((10 ** 6) + 1)

for elem in a:
    cnt[elem] += 1

unique = []

for i in range((10 ** 6) + 1):
    if cnt[i] == 1:
        unique.append(i)

cnt = [0] * ((10 ** 6) + 1)

a = list(set(a))

for elem in a:
    for m in range(elem * 2, (10 ** 6) + 1, elem):
        cnt[m] = 1

ans = 0

for elem in unique:
    if cnt[elem] == 0:
        ans += 1

print(ans)


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

int n;
double p[3001];
double DP[3001][3001];

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%lf", &p[i]);
    DP[1][0] = 1.0 - p[1];
    DP[1][1] = p[1];
    for(int i = 2; i <= n; i++){
        for(int j = 0; j <= i; j++){
            DP[i][j] = (DP[i-1][j]*(1.0 - p[i])) + (DP[i-1][j-1] * p[i]);
        }
    }
    double wynik = 0.0;
    for(int i = (n+1)/2; i <= n; i++){
        wynik += DP[n][i];
    }
    printf("%.10lf", wynik);
    return 0;
}


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

int main(){
    int N,index=0;
    int q=0; // 0:初期状態 1:縦並べ 2:横並べ
    long long int answer=1;
    char S1[60]={};
    char S2[60]={};

    cin >> N;
    cin >> S1 >> S2;

    while(index<N){
        switch(q){
            case 0:
                if(S1[index]==S2[index]){
                    answer*=3;
                    index+=1;
                    q=1;
                }
                else{
                    answer*=6;
                    index+=2;
                    q=2;
                }
                break;
            case 1:
                if(S1[index]==S2[index]){
                    answer*=2;
                    index+=1;
                    q=1;
                }
                else{
                    answer*=2;
                    index+=2;
                    q=2;
                }
                break;
            case 2:
                if(S1[index]==S2[index]){
                    answer*=1;
                    index+=1;
                    q=1;
                }
                else{
                    answer*=3;
                    index+=2;
                    q=2;
                }
                break;
        }
    }

    cout << answer%1000000007 << "\n";

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  int counter=0;
  for (int i=1; i<N+1; i++){
    int j=i;
    int clun=0;
    while(j>0){
      j/=10;
      clun++;}
    if (clun%2!=0) counter++;}
  cout<<counter<<endl;}

Measured memory_bytes: 256
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int t3 = x * 2 - y;
		int s3 = y * 2 - x;
		sc.close();
		if(t3 < 0 || t3 % 3 != 0 || s3 < 0 || s3 % 3 != 0) {
			System.out.println(0);
			return;
		}
		int t = t3 / 3;
		int s = s3 / 3;
		int mod = 1000000007;

		System.out.println(nCk(t + s, s , mod));

	}
	public static int nCk(int n,int k,int M) {
        long ret = 1;
        int min = Math.min(k, n-k);
        for(int i=1;i<=min;i++) {
            ret = (ret * pow(i,M-2,M)) % M;
        }
        for(int i=n-min+1;i<=n;i++) {
            ret = (ret * i) % M;
        }
        return (int)ret;
    }
	 public static long pow(long a,long b,int M) {
	        long ret = 1;
	        long tmp = a;
	        while(b>0) {
	            if((b&1)==1) ret = (ret * tmp) % M;  //2進数によるべき乗の高速計算
	            tmp = (tmp * tmp) % M;
	            b = b>>1;
	        }
	        return ret;
	    }
}



Measured memory_bytes: 35632
N, W = [int(i) for i in input().split()]
weight, value = [0] * (N + 1), [0] * (N + 1)

for i in range(1, N + 1):
    weight[i], value[i] = [int(i) for i in input().split()]
#%%
sum_value = sum(value)
dp = [[float("inf")] * (sum_value + 1) for _ in range(N + 1)]
dp[0][0] = 0

for i in range(1, N + 1):
    for j in range(sum_value + 1):
        if j >= value[i]:
            dp[i][j] = weight[i] + dp[i - 1][j - value[i]]
        
        dp[i][j] = min(dp[i][j], dp[i -1][j])
        
ans = 0
for i in range(sum_value + 1):
    if dp[N][i] <= W:
        ans = i

print(ans)


Measured memory_bytes: 312536
#!/usr/bin/env ruby

temp = [];matrixA = [];matrixB = []
lineresult = []

temp = gets.split.map(&:to_i)
Array_A_WIDTH = temp[0]
Arrays_HEIGHT = temp[1]
Array_B_WIDTH = temp[2]

Array_A_WIDTH.times do
    matrixA << gets.split.map(&:to_i)
end
Arrays_HEIGHT.times do
    matrixB << gets.split.map(&:to_i)
end

Array_A_WIDTH.times do |loopA|
    Array_B_WIDTH.times do |loopC|
        foo = 0
        Arrays_HEIGHT.times do |loopB|
            foo += matrixA[loopA][loopB] * matrixB[loopB][loopC]
        end
        lineresult << foo
    end
    puts lineresult.join(' ')
    lineresult.clear
end


Measured memory_bytes: 7320
N, M = gets.split.map(&:to_i)
ks_list = M.times.map { gets.split.map(&:to_i) }
p_list = gets.split.map(&:to_i)

ans = 0
(0..((1 << N) - 1)).each do |n|
  is_ok = M.times.all? do |i|
    k, *s_list = ks_list[i]
    on_count = 0
    s_list.each do |s|
      s -= 1
      on_count += 1 if n[s] == 1
    end
    on_count % 2 == p_list[i]
  end
  ans += 1 if is_ok
end
puts ans


Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int inf=1e9;
const LL mod=998244353;
#define mem(a,b) memset(a,b,sizeof(a))
int max(int a,int b) {return a>b?a:b;}

int main()
{
    int a[5];
    for(int i=0;i<4;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+4);
    if(a[0]==1&&a[1]==4&&a[2]==7&&a[3]==9) printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut n = line.trim().parse::<u32>().ok().unwrap();
    let mut flag = false;
    while n > 0 {
        if n % 10 == 7 {
            flag = true;
            break;
        }
        n /= 10
    }
    if flag {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

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

int main() {

  int n, x;
  cin >> n >> x;

  const int M = 666;
  vector<vector<int>> dp(M, vector<int>(x + 1));
  const int mod = 998244353;
  dp[0][0] = 1;

  auto f = [&]() {
    rep(j, M) {
      for (int k = 1; k <= x; k++) {
        dp[j][k] = (dp[j][k] + dp[j][k - 1]) % mod;
      }
    }
  };

  rep(i, n) {
    f();
    vector<vector<int>> nxt(M, vector<int>(x + 1));
    rep(j, M) {
      for (int k = 0; k <= x; k++) {
        if ((j ^ k) < M) {
          nxt[j ^ k][k] += dp[j][k];
          nxt[j ^ k][k] %= mod;
        }
      }
    }
    dp.swap(nxt);
  }

  f();
  cout << dp[x][x] << endl;

  return 0;
}


Measured memory_bytes: 5528
import java.util.Scanner;

public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        int n;
        double tmp;
        n=nextInt();
        tmp=1.0;
        while(n!=(int)(tmp*1.08)&&n>=tmp){
            tmp+=1;
        }
        if(n==(int)(tmp*1.08)){
            print((int)tmp);
        }
        else print(":(");
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
}

Measured memory_bytes: 21972
N, K = [int(i) for i in input().split()]
d = {}
for i in range(K):
    _ = int(input())
    tmp = [int(i) for i in input().split()]
    for j in tmp:
        d[j] = 1
ans = 0
for i in range(N):
    if not i + 1 in d:
        ans += 1
print(ans)

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

int H,W;

int used[111][111];

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

typedef long long ll;

bool check(int x,int y){
  if( x < 1 || y < 1 ) return true;
  vector<int> p;
  for(int i=0;i<4;i++)
    p.push_back( used[x+dx[i]][y+dy[i]] ); 
  sort(p.begin(),p.end());
  p.erase(unique(p.begin(),p.end()),p.end());

  if( p.size() == 4 ) return false;
  return true;
}

void view(){
  cout << "view" << endl;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout << used[j][i] << " ";
    }
    cout << endl;
  }
}

ll dfs(int x,int y,int cnt){

  if( x >= W ) return dfs(0,y+1,cnt);
  //  view();
  if( y >= H ){
    return 1LL;
  }
  ll res = 0;

  if( used[x][y] == -1 ){
    if( x + 1 < W && used[x+1][y] == -1 ){
      used[x][y] = cnt;
      used[x+1][y] = cnt;
      if( check( x, y ) ){
	res += dfs(x+1,y,cnt+1);
      }
      used[x][y] = -1;
      used[x+1][y] = -1;
    }
    if( y + 1 < H && used[x][y+1] == -1 ){
      used[x][y] = cnt;
      used[x][y+1] = cnt;
      if( check( x, y ) ){
	res += dfs(x+1,y,cnt+1);
      }
      used[x][y] = -1;
      used[x][y+1] = -1;
    }
  } else if( check(x,y) )
      return dfs(x+1,y,cnt);
  
  return res;
}

int main(){
  while( cin >> H >> W &&(W||H) ){
    memset(used,-1,sizeof(used));
    cout << dfs(0,0,0) << endl;
  }
}

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

  #define vi vector<int>
  #define all(v) v.begin(),v.end()
  #define ll long long int
  #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
  #define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}

  const ll MOD=1e9+7;

  void solve(){
     int n;
     cin >> n;
     vi v(n);
     for(int i=0;i<n;i++)cin >> v[i];
     sort(all(v));
     int ans =0;
    //  1 2 3 4
    //  1 2 3 4
    //  ^ ^
    D2(v);
     for(int j=n-1;j>=2;j--){
       int i=0,k=j-1;
       while(i<k){
          while(i<k && v[i]+v[k]>v[j])k--;
          ans += (j-k-1);
          i++;
       }
       int o = j-i;
       ans += max(0,(o*(o-1))/2);

     }
     cout << ans;
  }


  int main(){
    IOS
       solve();
       cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 3780
n = gets.chop.to_i
a = []
b = []
n.times do |i|
  a[i],b[i] = gets.chomp.split(" ").map(&:to_i)
end
a.reverse!
b.reverse!
x = 0
ans = 0
while(x < n)
  pl = (b[x] - ((a[x]+ans)%b[x]))%b[x]
  ans += pl
  x+=1
end
puts ans

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

ll d[300][300];
int main(void) {
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);

    int n, m, R;
    cin >> n >> m >> R;
    vector<ll> r;
    for(int i=0; i<R; i++){
        ll t;
        cin >> t;
        t--;
        r.pb(t);
    }

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i == j){
                d[i][j] = 0;
            }else{
                d[i][j] = INF;
            }
        }
    }

    for(int i=0; i<m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        d[a][b] = c;
        d[b][a] = c;
    }

    for(int k=0; k < n; k++){
        for(int i=0; i < n; i++){
            for(int j=0; j < n; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    ll ans = INF;
    sort(r.begin(), r.end());
    do{
        ll dis = 0;
        for(int i=0; i<R-1; i++){
            //printf("%d ", r[i]);
            dis += d[r[i]][r[i+1]];
        }
        //printf("%d\n", r[R-1]);
        ans = min(ans, dis);
    }while(next_permutation(r.begin(), r.end()));

    cout << ans << endl;


    
    return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;

  string s, t;
  cin >> s >> t;

  int match = s.length();
  rep(i, s.length()){

    bool ok = true;
    for(int j = 0; i+j < s.length() && j < t.length(); j++){
      if(s[i+j] != t[j]){
        ok = false;
        break;
      }
    }
    if(ok){
      chmin(match, i);
    }
  }

  cout << max(s.length(), match+t.length()) << endl;





  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<17,MAX_LOG=20,INF=1<<30;
vector<pair<int,ll>> G[MAX];
int N,par[MAX_LOG][MAX],depth[MAX];
ll dis[MAX];
vector<int> ord;

void BFS(int u){
    for(int i=0;i<N;i++){
        depth[i]=-1;
        dis[i]=0;
        for(int j=0;j<20;j++){
            par[j][i]=-1;
        }
    }
    queue<int> Q;
    Q.push(u);
    depth[u]=0;
    dis[u]=0;
    ord.push_back(u);
    while(!Q.empty()){
        int a=Q.front();
        Q.pop();
        for(int i=0;i<G[a].size();i++){
            int b=G[a][i].first;
            ll c=G[a][i].second;
            if(depth[b]==-1){
                depth[b]=depth[a]+1;
                dis[b]=dis[a]+c;
                par[0][b]=a;
                Q.push(b);
                ord.push_back(b);
            }
        }
    }
    return;
}

void init(){
    for(int k=0;k+1<MAX_LOG;k++){
        for(int i=0;i<N;i++){
            if(par[k][i]<0) par[k+1][i]=-1;
            else par[k+1][i]=par[k][par[k][i]];
        }
    }
}

int lca(int u,int v){
    if(depth[u]>depth[v]) swap(u,v);
    for(int i=0;i<20;i++){
        if(((depth[v]-depth[u])>>i)&1) v=par[i][v];
    }
    if(u==v) return u;
    
    for(int i=19;i>=0;i--){
        if(par[i][u]!=par[i][v]){
            u = par[i][u];
            v = par[i][v];
        }
    }
    return par[0][u];
}
//BFS(u)->init()で呼ぶ


int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    for(int i=1;i<N;i++){
        int a;cin>>a;
        a--;
        G[a].push_back({i,1});
        G[i].push_back({a,1});
    }
    
    for(int i=0;i<N;i++) sort(all(G[i]));
    
    BFS(0);
    init();
    
    ll ans=0;
    
    for(int i=1;i<N;i++){
        ans+=dis[ord[i-1]]+dis[ord[i]]-2*dis[lca(ord[i-1],ord[i])];
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 21188
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;
typedef  pair<int,int> pa;
int dv[][2]={{0,1},{1,0},{-1,0},{0,-1}};
int mod=1e9+7;
const int N=2e5+100;

int main()
{
   int ans=0;
   int n;cin>>n;
   int k=0;
   int a[N];
   for(int i=1;i<=n;i++) scanf("%d",&a[i]);
   for(int i=1;i<n;i++){
     if(a[i]>=a[i+1]) k++;
     else {ans=max(ans,k),k=0;}
   }
   ans=max(k,ans);
   cout<<ans;
   return 0;
}


Measured memory_bytes: 640
x,y,a,b,c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

l = p[:x]
l.extend(q[:y])
l.extend(r)
l.sort(reverse=True)
ans = sum(l[:x+y])

print(ans)


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

using namespace std; 

int main() {
  int n; 
  cin>>n; 
  int k; 
  cin>>k;
  int a[n]; 
  int i; 
  for(i=0;i<n;i++) { 
    cin>>a[i]; 
  } 
  if (n== 0) {
    cout<<0<<endl; 
    return 0;
  }
  else if (n == 1) { 
    cout<<0<<endl;
    return 0;
  } 
  vector<int> dp(n,0);
  for (i=1;i<n;i++) { 
    dp[i] = dp[i-1] + abs(a[i] - a[i-1]); 
    for (int j=max(0, i-k); j<i-1;j++)
       dp[i] = min(dp[i], dp[j] + abs(a[j] - a[i])); 
  }
  cout<<dp[n-1]<<endl;
  return 0;
  
  }


Measured memory_bytes: 1152