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

using namespace std;

int main()

{
    long long int i,j,k,l,n,m,o,p;


    while(cin>>n)
    {
        long long int a[n];
        k=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            k+=a[i];
        }
        printf("%lld\n",k-n);
    }

}





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

using namespace std;

int main() {
   
    long long  arr[1000000],k;
    double a,n,t,l,m=1000000;
    cin >> n>>t>>a;
    for(long long i=0;i<n;i++){
        cin >> arr[i];
    }
    
   for(long long i=0;i<n;i++){
       l=t-arr[i]*(0.006);
       l=abs(a-l);
      // cout << l<<"*";
       if(l<m){
           m=l;
           k=i+1;
       }
       }
       cout << k;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll N, M;
string S, T;

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

ll lcm(ll m, ll n) {
    if ((0 == m) || (0 == n)) return 0;
    return ((m / gcd(m, n)) * n);
}

void solve() {
    ll L = lcm(N, M);
    REP(i, M / (L / N)) {
        if (S[L / M * i] != T[L / N * i]) {
            cout << "-1" << endl;
            return;
        }
    }
    cout << L << endl;
}

int main() {
    cin >> N >> M;
    cin >> S >> T;
    solve();
    return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")

#include <bits/stdc++.h>
using namespace std;

int c[26];
int64_t csum;
int64_t s[366][26];

int64_t eval(const vector<int> &state, int d){
    int last[26] = {0};
    int64_t decl = -csum;
    int64_t score = 0;

    for(int i=1;i<=d;++i){
        score += s[i][state[i]];
        decl += (i - last[state[i]])*c[state[i]];
        last[state[i]] = i;
        score += decl;
        decl -= csum;
    }
    return score;
}

vector<int> beam(int D, int w){
    map<int64_t, vector<int>, greater<int64_t>> mp;
    for(int i=0;i<26;++i){
        mp[s[1][i] + c[i] - csum] = vector<int>{2, i};
    }
    for(int d=2;d<=D;++d){
        int cnt = 0;
        vector<vector<int>> states;
        for(auto p: mp){
            states.push_back(p.second);
            ++cnt;
            if(cnt >= w) break;
        }
        mp.clear();
        for(auto v: states){
            for(int i=0;i<26;++i){
                vector<int> state{v};
                state.emplace_back(i);
                mp[eval(state, d)] = state;
            }
        }
    }
    return mp.begin()->second;
}

int main(){
    int d;
    scanf("%d", &d);
    for(int i=0;i<26;++i) scanf("%d", &c[i]);
    for(int i=0;i<26;++i) csum += c[i];

    for(int i=1;i<=d;++i){
        for(int j=0;j<26;++j) scanf("%" SCNd64, &s[i][j]);
    }

    auto ans = beam(d, 270);
    for(int i=1;i<=d;++i) printf("%d\n", ans[i] + 1);

    return 0;
}

Measured memory_bytes: 13560
k = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字
def gcd(x, y): #GCD
    # greatest_common_divisor
    if x < y:
        x, y = y, x
    if y == 0:
        return 0
    if x % y == 0:
        return y
    return gcd(y, x % y)

temp = []
for i in range(1, k + 1):
    for j in range(1, k + 1):
        temp.append(gcd(i, j))
from collections import Counter
c = Counter(temp)
ans = 0
for t, v in c.items():
    for n in range(1, k + 1):
        ans += gcd(t, n) * v
print(ans)


Measured memory_bytes: 78260
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int N;
    cin>>N;
    //愚直に探す
    //N<10000よりx<=y<=zとするとxは最高でも100
    vector<int> ans(N+1);
        for(int x=1;x<=100;x++){
            for(int y=1;y<=100;y++){
                for(int z=1;z<=100;z++){
                    int v=x*x+y*y+z*z+x*y+y*z+z*x;
                    if(v<=N){
                        ans[v]++;
                    }else{
                        break;
                    }
                }
            }
        }
    
    for(int i=1;i<N+1;i++){
        cout << ans[i] << endl;
    }
    return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    int s[105];
    for(int i = 1; i <= n; i++){
        cin >> s[i];
    }
    bool dp[105][10005];
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= 10000; j++){
            dp[i][j] = false;
        }
    }
    dp[0][0] = true;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= 10000; j++){
            dp[i][j] = dp[i - 1][j];
            if(j >= s[i]){
                dp[i][j] = dp[i][j] or dp[i - 1][j - s[i]];
            }
        }
    }
    for(int i = 10000; i >= 0; i--){
        if(i % 10 == 0) continue;
        if(dp[n][i]){
            cout << i << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a,b;
cin>>a>>b;
for(int i=1;i<=10004;i++)
{
  int res=i*(0.08);
  int val=i*(0.1);
  if(res==a&&val==b)
  {
      cout<<i<<endl;
      return 0;
  }
}
cout<<-1<<endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<pair<int,int>> a(n,pair<int,int> (0,0));
  for(int i=0;i<n;i++) {
    int x,y;
    cin >> x >> y;
    a.at(i)=pair<int,int> (x,y);
  }
  vector<pair<int,int>> b(n,pair<int,int> (0,0));
  for(int i=0;i<n;i++) {
    int x,y;
    cin >> x >> y;
    b.at(i)=pair<int,int> (x,y);
  }
  sort(a.rbegin(),a.rend());
  sort(b.begin(),b.end());
  int count=0;
  for(int i=0;i<n;i++){
    int temp_y=-1;
    int temp_id=-1;
    for(int j=0;j<a.size();j++) {
      if(a.at(j).first<b.at(i).first
      &&a.at(j).second<b.at(i).second) {
        if(temp_y<a.at(j).second) {
          temp_y=a.at(j).second;
          temp_id=j;
        }
      }
    }
    if(temp_id!=-1) {
      count++;
      a.erase(a.begin()+temp_id);
    }
  }
  cout << count << endl;
}

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

int main () {
	int k; cin >> k;
	queue <LL> q;
	for (LL i = 1; i <= 9; i ++) {
		q.push (i);
	}
	LL x;
	while (k > 0) {
		x = q.front (); q.pop ();
		k --;
		int d = x % 10;
		if (d) q.push (x * 10 + d - 1);
		q.push (x * 10 + d);
		if (d < 9) q.push (x * 10 + d + 1);
	}
	cout << x;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<math.h>
using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A - B >= C) {
		cout << 0;
		return 0;
	}
	else {
		cout << C - A + B;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
void hai();
int main(void)/**配列の要素数を決める。**/{
	int N;//変数宣言
	scanf("%d",&N);//配列の要素数を決める。

	hai(N);//配列の要素数を引数とし、配列の要素を入れる関数
}

void hai(int N){
	int *hai,i,hairetsu[N],j,k;
	int value;

	hai=hairetsu;

	for(i=0;i<N; i++){

		scanf("%d",&hai[i]);
		printf("%d",hai[i]);
		if(i!=N-1)printf(" ");

	}
	printf("\n");

	for(i=1;i<N;i++){

		value=hai[i];//i列目を変数に記憶させる。
		j=i-1;
		while((j>=0)&&(hai[j]>value)){
			hai[j+1]=hai[j];

			j--;

		}
		hai[j+1]=value;

		for(k=0;k<N;k++){
		    if(k == N-1)printf("%d\n",hai[k]);
		    else printf("%d ",hai[k]);
		}

	}


}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a[100]={2,1};
	cin>>n;
	for(int i=2;i<=n;i++)
	a[i]=a[i-1]+a[i-2];
	cout<<a[n];
	return 0;
}

Measured memory_bytes: 256
fn main() {
    proconio::input! {
        n: usize,
        s: [String; n],
    }
    let mut h = std::collections::HashMap::new();
    for s in s {
        *h.entry(s).or_insert(0) += 1;
    }
    let ans = format!(
        "AC x {}\nWA x {}\nTLE x {}\nRE x {}",
        h.get("AC").or(Some(&0)).unwrap(),
        h.get("WA").or(Some(&0)).unwrap(),
        h.get("TLE").or(Some(&0)).unwrap(),
        h.get("RE").or(Some(&0)).unwrap()
    );
    println!("{}", ans);
}


Measured memory_bytes: 7904
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    long long X, K, D;
    cin >> X >> K >> D;

    long long ll_a;
    ll_a = X / D;
    if (ll_a < 0)
    {
        ll_a = -ll_a;
    }
    if (ll_a > K)
    {
        ll_a = K;
    }

    long long ll_b;
    if (X < 0)
    {
        ll_b = X + ll_a * D;
    }
    else
    {
        ll_b = X - ll_a * D;
    }

    if (ll_b < 0)
    {
        ll_b = -ll_b;
    }

    long long ret;
    if (((ll_a - K) % 2) == 0)
    {
        ret = ll_b;
    }
    else
    {
        ret = ll_b - D;
        if (ret < 0)
        {
            ret = -ret;
        }
    }

    cout << ret << "\n";
}


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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

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

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* 
	add utility Algorithm
*/

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, i;
    cin >> N >> i;
    cout << (N - i + 1) << endl;

    return 0;
}


Measured memory_bytes: 3508
N = int(input())
max = 0
length = 0
alphabet = 'abcdefghijklmnopqrstuvwxyz'
name = ""

i = 0
while True:
  i += 1
  max += 26**i
  length = i
  if N <= max:
    break

index_10 = N - (max - 26**i) -1

for j in range(length):
  index = index_10 % 26
  index_10 //= 26
  alphabet[index]
  name = alphabet[index] + name

print(name)

Measured memory_bytes: 9184
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    int n;
    cin >> n;
    map<string, int> mp;
    int top = 0;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        top = max(top, ++mp[s]);
    }
    for (auto p : mp) {
        if (p.second == top) cout << p.first << '\n';
    }

    return 0;
}

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

template<typename T>
T gcd(T a, T b){
    if (b==0) return a;
    else return  gcd(b,a%b);
}

template<typename T>
T lcm(T a, T b){
    return a* (b / gcd<T>(a,b));
}


void solve(long long N, std::vector<long long> T){
    ll ret = 1;
    for (const auto &a: T){
        ret = lcm<ll>(ret,a);
    }
    printf("%lld\n",ret);

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> T(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&T[i]);
    }
    solve(N, std::move(T));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    int N, val;
    cin >> N;
    vector<vector<int>> arr(N+1, vector<int>(N-1));
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N-1; j++) {
            cin >> arr[i+1][j];
        }
    }
    vector<int> idx(N+1, 0);
    vector<pair<int, int>> dq;
    for(int i = 1; i <= N; i++) {
        if (idx[i] < N-1) {
            int tar = arr[i][idx[i]];
            if (idx[tar] < N-1 && arr[tar][idx[tar]] == i && i < tar) {
                dq.push_back({i, tar});
            }
        }
    }
    int ans = 0;
    int used = N*(N-1);
    while (!dq.empty()) {
        ans += 1;
        vector<pair<int, int>> new_dq;
        vector<int> nodes;
        used -= dq.size() * 2;
        for(auto& p: dq) {
            idx[p.first] += 1;
            idx[p.second] += 1;
            nodes.push_back(p.first);
            nodes.push_back(p.second);
            // cout << "round: " << ans << ", del " << p.first << " :" << p.second << endl;
        }

        vector<bool> visit(N+1, false);
        for(auto& src: nodes) {
            if (idx[src] >= N-1) continue;
            int dst = arr[src][idx[src]];
            if (idx[dst] < N-1 && idx[src] < N-1 && !visit[src] && !visit[dst] &&
                arr[dst][idx[dst]] == src) {
                    visit[dst] = true;
                    visit[src] = true;
                    new_dq.push_back({src, dst});
                }
        }
        dq.swap(new_dq);
    }
    if (used == 0) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}



Measured memory_bytes: 4224
import sys
input = sys.stdin.readline
N=int(input())
strings=list("".join(sorted(input())) for _ in range(N))
string_set = set()
counts = {}
count = 0
for string in strings:
    if string in string_set:
        count += counts[string]
        counts[string] += 1
    else:
        string_set.add(string)
        counts[string] = 1

print(count)

Measured memory_bytes: 23560
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int top = 0; S[1000];
void push(int x){
	S[++top] = x;
}
int pop(void){
	top--;
	return S[top+1];
}
int main(void){
	int a,b;
	top = 0;
	char s[100];
	while(scanf("%s",s) != EOF){
		if(s[0] == '+'){
			a = pop();
			b = pop();
			push(a+b);
		}
		else if(s[0] == '-'){
			b = pop();
			a = pop();
			push(a-b);
		}
		else if(s[0] == '*'){
			a = pop();
			b = pop();
			push(a*b);
		}
		else{
			push(atoi(s));
		}
	}
	printf("%d\n",pop());
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int x;
    cin >> x;
    int h=x/100,r=x%100;
    if(h>=(r+4)/5) print(1);
    else print(0);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll n,a,b,c;
vi num(100);
ll ans=llINF;
void dfs(ll depth,vi aa,vi bb,vi cc){
  if(depth == n){
    if(aa.size()==0 || bb.size()==0 || cc.size()==0)return;
    ll cost=10*(max(0LL,(ll)aa.size()-1)+max(0LL,(ll)bb.size()-1)+max(0LL,(ll)cc.size()-1));
    ll aaa=0,bbb=0,ccc=0;
    for(auto A:aa)aaa+=A;
    for(auto A:bb)bbb+=A;
    for(auto A:cc)ccc+=A;
    ans=min(ans,cost+abs(aaa-a)+abs(bbb-b)+abs(ccc-c));
    ans=min(ans,cost+abs(aaa-a)+abs(ccc-b)+abs(bbb-c));
    ans=min(ans,cost+abs(bbb-a)+abs(aaa-b)+abs(ccc-c));
    ans=min(ans,cost+abs(bbb-a)+abs(ccc-b)+abs(aaa-c));
    ans=min(ans,cost+abs(ccc-a)+abs(bbb-b)+abs(aaa-c));
    ans=min(ans,cost+abs(ccc-a)+abs(aaa-b)+abs(bbb-c));
    return;
  }
  aa.pb(num[depth]);
  dfs(depth+1,aa,bb,cc);
  aa.pop_back();
  bb.pb(num[depth]);
  dfs(depth+1,aa,bb,cc);
  bb.pop_back();
  cc.pb(num[depth]);
  dfs(depth+1,aa,bb,cc);
  cc.pop_back();
  dfs(depth+1,aa,bb,cc);
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>a>>b>>c;
  for(int i=0;i<n;i++)cin>>num[i];
  vi aa,bb,cc;
  dfs(0,aa,bb,cc);
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;
using ll = long long;

int main()
{
    int N, C;
    cin >> N >> C;

    vector<int> s(N);
    vector<int> t(N);
    vector<int> c(N);

    int T = 0;

    for (int i = 0; i < N; ++i) {
        cin >> s[i] >> t[i] >> c[i];
        --c[i];

        T = max(T, t[i]+1);
    }

    vector<int> v(T+2, 0);

    for (int nc = 0; nc < C; ++nc) {
        vector<int> u(T+2, 0);

        for (int i = 0; i < N; ++i) {
            if (c[i] == nc) {
                ++u[s[i]];
                --u[t[i] + 1];
            }
        }

        for (int i = 0; i < T; ++i) {
            u[i+1] += u[i];
        }

        for (int i = 0; i <= T; ++i) {
            if (u[i] > 0) { 
                ++v[i];
            }
        }
    }

    int ans = 0;
    for (int i = 0; i <= T; ++i) {
        ans = max(ans, v[i]);
    };

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll x,y,z,a,b;
	cin >> x >> y >> z;
	x=x-2*z;
	a=y+z;
	b=0ll;
	if(x%a>=y){
		b=1ll;
	}
	cout << x/a+b << endl;


	return 0;
}

Measured memory_bytes: 256
a,b,c = gets.split(' ').map { |e| e.to_i }

i = 1
ms = []
while true
  m = (a * i) % b
  if m == c
    puts 'YES'
    break
  elsif ms.any? { |i| i == m }
    puts 'NO'
    break
  else
    ms << m
  end
  i += 1
end



Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0 ; i < (int)(n) ; i++)
typedef long long ll;
////////////////////////////////////////////////
int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int ans = 0;
    rep(i,n+1){
        int cnt = 0, k = i;
        rep(j,5){
            cnt += (k % 10);
            k /= 10;
        }
        if (a <= cnt && cnt <= b) ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
lines.shift()
lines.pop()
l = lines.map((x, i) => {
    a = x.split(' ').map(x => x * 1)
    a.i = i
    return a
}).sort((a, b) => {
  return a[0] == b[0] ? a[1] - b[1] : a[0] - b[0]
})

arr = []
y = ''
for (i=0; i<l.length; i++) {
    if (y != l[i][0]) {
        j = 1 
        y = l[i][0]
    }
    arr[l[i].i] = ('000000' + l[i][0]).slice(-6) + ('000000' + j).slice(-6)
    j++
}
console.log(arr.join('\n'))

Measured memory_bytes: 83236
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define loop(i) for(int i = 0;true; i++)
#define all(x) (x).begin(), (x).end()
#define yn(f) (f?"yes":"no")
#define YN(f) (f?"YES":"NO")
#define Yn(f) (f?"Yes":"No")
#define mn 1000000007
int main() {
	int N, M;
	cin >> N;
	cin >> M;
	vvi A(N);
	for (int i = 0; i < M; i++)
	{
		int l, r;
		scanf("%d", &l);
		scanf("%d", &r);
		A[l].push_back(r);
		A[r].push_back(l);
	}
	vi C(N, -1);
	vi v(N, 0);
	int num = 0;
	for (int i = 0; i < N; i++)
	{
		if (v[i]) {
			continue;
		}
		else {
			v[i] = 1;
			num++;
			C[i] = num;
		}
		stack<int> S;
		S.push(i);
		while (!S.empty()) {
			int temp = S.top();
			S.pop();
			for (int j = 0; j < A[temp].size(); j++)
			{
				if (v[A[temp][j]] == 0) {
					S.push(A[temp][j]);
					v[A[temp][j]] = 1;
					C[A[temp][j]] = num;
				}
			}

		}
	}
	for (int i = 0; i < N; i++)
	{
		
	}
	int k;
	cin >> k;
	for (int i = 0; i < k; i++)
	{
		int l, r;
		scanf("%d", &l);
		scanf("%d", &r);

		printf("%s\n", yn(C[l] == C[r]));
	}
};



Measured memory_bytes: 9184
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	rep(i, 1, n) {
		int cou = 0;
		string a = s.substr(0, i);
		string b = s.substr(i);
		set<char> st;
		rep(j, 0, a.size()) {
			if (!st.count(a[j]) && count(all(b), a[j])) {
				cou++;
			}
			st.insert(a[j]);
		}
		ans = max(ans, cou);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().rstrip().split())
As = [int(x) for x in input().rstrip().split()]
# print(N, M)
# print(As)
total = sum(As)
count = len([True for x in As if x >= total / (4*M) ])
if count >= M:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define black_tree tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define pair_black_tree tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update>
#define gp __gnu_pbds
#define INF 1000000000
#define MOD 1000000007
#define MAX 1000001
#define endl '\n'
#define ll long long
#define ld long double
#define lli long long int
#define ull unsigned long long
#define ulli unsigned long long int
#define pb push_back
#define pf push_front
#define ook order_of_key
#define fbo find_by_order
#define np next_permutation
#define mp make_pair
#define eb emplace_back
#define mae max_element
#define mie min_element
#define lb lower_bound 
#define ub upper_bound
#define bs binary_search
#define ff first
#define ss second
using namespace std;
using namespace gp;
ll n;
ll q(ll a,ll b){
	ll f=1;
	while(b!=0){
        if(b%2==1){
        	f=(f*a)%MOD;
		}
        b>>=1;
        a=(a*a)%MOD;
	}
	return f;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    cout<<(q(10,n)-(2LL*q(9,n)-q(8,n))%MOD+MOD)%MOD;
}

Measured memory_bytes: 3620
# (c) midandfeed
while(True):
	h, w = [int(x) for x in input().split()]
	
	if (h == 0) and (w==0):
		break
		
	for i in range(1, h+1):
		if (i==1) or (i==h):
			print("#"*w)
		else:
			print("{}{}{}".format("#", "."*(w-2), "#"))
	print()
	
	# for i in range(1, h+1):
		# for j in range(1, w+1):
			# if (i==1) or (i == h):
				# print("#", end='')
			# else:	
				# if (j==1) or (j==w):
					# print("#", end='')
				# else:
					# print(".", end='')
		# print()
	# print()

Measured memory_bytes: 7768
#include <iostream>

void drawLine(int W, int lineNum) {
	int written = 0;
	if (lineNum % 2 == 0) {
		std::cout << "."; 
		written++;
	}
	while (written < W) {
		std::cout << "#";
		written++;
		if (written >= W)
			break;
		std::cout << ".";
		written++;
	}
	std::cout << "\n";
}

void drawChessboard(int H, int W) {
	for (int i = 1; i <= H; i++) {
		drawLine(W, i);
	}
	std::cout << "\n";
}

int main()
{
	int H, W;
	std::cin >> H >> W;
	while (H != 0 || W != 0) {
		drawChessboard(H, W);
		std::cin >> H >> W;
	}
    return 0;
}




Measured memory_bytes: 3080
from collections import defaultdict
d = defaultdict(int)

n, k, q = map(int, input().split())


for _ in range(q):
    d[int(input())] += 1

for x in range(1, n+1):
    if k - q + d[x] > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 62296
package main
 
import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}
 
//func nextString() string {
//	sc.Scan()
//	return sc.Text()
//}
 
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	N := nextInt()
	m := make(map[int]int, N)
	var n int
	for i := 1; i <= N; i++ {
		n = nextInt()
		m[n] = i
	}
	for i := 1; i < N; i++ {
		fmt.Printf("%d ", m[i])
	}
	fmt.Printf("%d\n",m[N])
}

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

using namespace std;

vector<int> adj[100005];
vector<int> dp;

int f(int u){
	if(dp[u] != -1)
		return dp[u];
	dp[u] = 0;
	for(int i=0;i<adj[u].size();i++){
		int v = adj[u][i];
		dp[u] = max(dp[u], f(v)+1);
	}
	return dp[u];
}

int main(){
	int n, m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a, b;
		cin>>a>>b;
		adj[a].push_back(b);
	}
	dp.assign(n+1, -1);
	int ans = 0;
	for(int i=1;i<=n;i++){
		ans = max(ans, f(i));
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 8192
package main

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

func main() {
	scan_init()
	n := scanInt()
	if n == 0 {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}
}

var sc = bufio.NewScanner(os.Stdin)

func scan_init() {
	sc.Split(bufio.ScanWords)
}
func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func scan() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 200000)

func readLine() string {
	buf := make([]byte, 0, 200000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
func readLineToNumber() int {
	S := readLine()
	number, _ := strconv.Atoi(S)
	return number
}
func readLineToSlice() []string {
	S := readLine()
	list := strings.Split(S, "")
	return list
}
func readLineToNumberSlice(memo map[string]int) []int {
	// err時は-1を代入
	S := readLine()
	intList := make([]int, len(S))
	for i := 0; i < len(S); i++ {
		if val, ok := memo[string(S[i])]; ok {
			intList[i] = val
		} else {
			intList[i] = -1
		}
	}
	return intList
}

Measured memory_bytes: 1784
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define all(v) (v).begin(),v.end()
#define fi first
#define se second
set<string> c;
map<ll,ll> mp;
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
int main(){
int n;
cin>>n;
vector<ll> b(n-1);
ll mi=inf;
for(int i=0;i<n-1;i++){cin>>b.at(i);}
ll ans=b.at(0);
for(int i=1;i<n-1;i++){
   if(b.at(i-1)<=b.at(i))ans+=b.at(i-1);
   else ans+=b.at(i);
   //if(b.at(i-1)<b.at(i)&&b.at(i)>b.at(i+1))ans+=max(b.at(i-1),b.at(i+1));
   //else ans+=b.at(i);
}
ans+=b.at(n-2);
cout<<ans<<endl;
}


Measured memory_bytes: 256
H, W, K = map(int,input().split())
c = []
for i in range(H): c.append(input())

ans = 0

for i in range(2 ** H):
    for k in range(2 ** W):
        black = 0
        for j in range(H):
            if (i >> j) & 1:
                for l in range(W):
                    if (k >> l) & 1:
                        if c[j][l] == "#":
                            black += 1
        if black == K: ans += 1
print(ans)


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

#define scd second
#define fst first
#define pb push_back
#define mkp make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef list<int> lint;
typedef list<ll> llong;
typedef list<pii> lpii;
typedef list<pll> lpll;
typedef list<lint> llint;
typedef list<llong> lllong;

int const N=1e6+100;
ll const LINF=numeric_limits<long long int>::max();
int const INF=numeric_limits<int>::max();
int const BN = 31;

ll gcd(ll a, ll b){
	return b ? gcd(b,a%b) : a;
}

ll pow_mod(ll a, ll e, ll m){
	ll res=1;
	while(e){
		if(e&1) res=res*a%m;
		a=a*a%m;
		e>>=1;
	}
	return res;
}

ll inv_mod(ll b, ll m){
	b%=m;
	ll x=0, y=1, r, q, a=m;
	while(b){
		q=a/b;
		r=a%b;
		a=b;
		b=r;
		r=x;
		x=y;
		y=r-q*y;
	}
	x+=m;
	return x%m;
}

void dfs(int r, vint gr[], vlong &xsum, vlong &ans, ll psum, vint &vst){
	psum+=xsum[r];
	ans[r]=psum;
	vst[r]=0;
	for(auto x : gr[r]){
		if(vst[x]==1){
			dfs(x,gr,xsum,ans,psum,vst);
		}
	}
}

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

	ll a, b;
	cin>>a>>b;
	ll s=1, ans=0;
	while(s<b){
		s=s-1+a;
		ans++;
	}
	cout<<ans<<endl;
}

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

using namespace std;

class UnionFind
{
	vector<int> par;
	vector<int> rk;
public:
	UnionFind(int n)
	{
		par.resize(n);
		rk.resize(n);
		for (int i = 0; i < n; ++i)
		{
			par[i] = i;
			rk[i] = 0;
		}
	}
	int find(int x)
	{
		if (par[x] == x)
		{
			return(x);
		}
		return(par[x] = find(par[x]));
	}
	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);
		if (x == y)
		{
			return;
		}
		if (rk[x] < rk[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (rk[x] == rk[y])
			{
				++x;
			}
		}
	}
	bool same(int x, int y)
	{
		return(find(x) == find(y));
	}
};

void solve()
{
	int N, K;
	cin >> N >> K;
	UnionFind uf(N + 1);
	vector< vector<int> > bunny(K);
	for (int i = 0; i < K; ++i)
	{
		int m;
		cin >> m;
		for (int j = 0; j < m; ++j)
		{
			int b;
			cin >> b;
			bunny[i].push_back(b);
		}
	}
	for (int i = 0; i < K; ++i)
	{
		for (int j = 1; j < bunny[i].size(); ++j)
		{
			uf.unite(bunny[i][0], bunny[i][j]);
		}
	}
	set<int> NGBunny;
	int R;
	cin >> R;
	for (int i = 0; i < R; ++i)
	{
		int p, q;
		cin >> p >> q;
		if (uf.same(p, q))
		{
			NGBunny.insert(p);
			NGBunny.insert(q);
		}	
	}
	cout << NGBunny.size() << endl;
}

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

Measured memory_bytes: 1216
N, M = map(int, input().split())
k=[]
s=[]
for i in range(M):
    input_tmp = list(map(int, input().split()))
    k.append(input_tmp[0])
    s.append(input_tmp[1:])
p=list(map(int, input().split()))

ans =0
for i in range(2**N):
    s_state=[]
    for j in range(N):
        s_state.append(i//(2**j)%2)
    all_green=1
    for j in range(M):
        num_on = 0
        for k in s[j]:
            num_on = num_on+s_state[k-1]
        if num_on%2 == p[j]:
            pass
        else:
            all_green=0
            break
    ans = ans + all_green
print(ans)

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int A,B,C,D;
    while(~scanf("%d %d %d %d",&A,&B,&C,&D))
    {
        if(A==B&&C>D)
            printf("%d",A+D);
        if(A==B&&C==D)
            printf("%d\n",A+C);
        if(A==B&&C<D)
            printf("%d\n",A+C);
        if(A>B&&C>D)
            printf("%d\n",B+D);
        if(A>B&&C==D)
            printf("%d\n",B+C);
        if(A>B&&C<D)
            printf("%d\n",B+C);
        if(A<B&&C>D)
            printf("%d\n",A+D);
        if(A<B&&C==D)
            printf("%d\n",A+C);
        if(A<B&&C<D)
            printf("%d\n",A+C);
    }
    return 0;
}


Measured memory_bytes: 128
N = int(input())
S = input()
left = 0
right = 0
k = 0
for c in S:
    if c == "(":
        left += 1
    else:
        right += 1
        if left < right:
            left = right
            k += 1
ans = ""
for i in range(k):
    ans += "("
ans += S
for i in range(left-right):
    ans+=")"
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
	long n;cin>>n;
    long og=0;
    double bg = 0;
    for(int i = 0;i<n;i++){
      double x;
      string u;
      cin>>x>>u;
      if(u == "JPY") og += x;
      if(u == "BTC") bg+= x;
    }
    bg = bg*380000.0;
    cout<<og+bg;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  
  vector<int> L(N);
  for(int i=0;i<N; i++){
    cin >> L.at(i);
  }
  //sort(L.begin(), L.end());//小さい順(昇順)に並び替え
  sort(L.begin(), L.end(), greater<int>());//大きい順(降順)に並び替え
  //for(int i=0; i<N; i++){
  //  cout<<"L.at("<<i<<") : "  << L.at(i) << endl;
  //}
  
  
  int ans = 0;
  //bool is_can = false; //三角形ができるならtrue
  for(int a=0; a<N-2; a++)
  {
    for(int b=a+1; b<N-1; b++)
    {
      for(int c=b+1; c<N;c++)
      {
        //if(is_can==false) continue;
        //is_can = false;
        //if(L.at(a) >= L.at(b) + L.at(c)) continue;//条件(a<b+c)を満たさないなら次へ
        //if(L.at(b) >= L.at(c) + L.at(a)) continue;//条件(b<c+a)を満たさないなら次へ
        //if(L.at(c) >= L.at(a) + L.at(b)) continue;//条件(c<a+b)を満たさないなら次へ
        //if(L.at(c) >= L.at(a) + L.at(b)) continue;//(cは最大辺)条件(c<a+b)を満たさないなら次へ
		
        //(aが最大辺なので，cをどれだけ小さくしても三角形はできないため，breakして次のbに行く
        if(L.at(a) >= L.at(b) + L.at(c)) break;//条件(a<b+c)を満たさないなら次へ
        ans++;
      }
    }
  }

  cout << ans << endl;
 
}


Measured memory_bytes: 256
/*
ID: jerrywcy
TASK: AtCoder ABC 099 Problem A
LINK: https://abc099.contest.atcoder.jp/tasks/abc099_a
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

int n;

int main()
{
	cin>>n;
	if (n<1000)cout<<"ABC"<<endl;
	else cout<<"ABD"<<endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll a, b; string s; cin >> a >> b >> s;
    bool ans = true;
    rep(i, a) if(!isdigit(s[i])) ans = false;
    if(s[a] != '-') ans = false;
    for(ll i=a+1; i<s.size(); i++){
        if(!isdigit(s[i])) ans = false;
    }
    (ans) ? Yes() : No();
}

Measured memory_bytes: 256
N, = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
R = 0
for i in range(N):
    x = X[i]
    for j in range(i+1, N):
        y = X[j]
        if x == y:
            continue
        for k in range(j+1, N):
            z = X[k]
            if x == z or y == z:
                continue
            if x+y>z:
                R += 1
print(R)



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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1<<25;
const ll INFL = 1223372036854775807;
const ll mod = 1000000007;



struct UnionFind {
	vector<int> par;
	int cnt;
	UnionFind(int size_) : par(size_, -1), cnt(size_) { }
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x != y) {
			if (par[y] < par[x]) swap(x, y);
			par[x] += par[y]; par[y] = x;
			cnt--;
		}
		return x != y;
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int find(int x) {
		return par[x] < 0 ? x : par[x] = find(par[x]);
	}
	int size(int x) {
		return -par[find(x)];
	}
	int size() {
		return cnt;
	}
};



int main() {
	int n;
	cin >> n;
	
	VVLL x(n, VLL(2)), y(n, VLL(2));

	REP(i, n) {
		cin >> x[i][0] >> y[i][0];
		x[i][1] = i;
		y[i][1] = i;
	}

	sort(ALL(x));
	sort(ALL(y));


	UnionFind uf(n);

	ll ans = 0;

	priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> q;

	REP(i, n - 1) {
		q.push(make_pair(x[i + 1][0] - x[i][0], x[i + 1][1] * n + x[i][1]));
		q.push(make_pair(y[i + 1][0] - y[i][0], y[i + 1][1] * n + y[i][1]));
	}

	while (!q.empty()) {
		pair<ll, ll>p = q.top();
		q.pop();
		if (!uf.same(p.second / n, p.second%n)) {
			uf.unite(p.second / n, p.second%n);
			ans += p.first;
		}
	}

	
	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 17780
import fileinput

def lcs(a, b):
    lcs_table = []

    def get_lcs(a_idx, b_idx):
        if a_idx < 0 or b_idx < 0:
            return 0
        else:
            return lcs_table[a_idx][b_idx] 

    for a_idx, last_a in enumerate(a):
        lcs_table.append([0] * len(b))
        for b_idx, last_b in enumerate(b):
            if last_a == last_b:
                new_lcs = get_lcs(a_idx - 1, b_idx - 1) + 1
            else:
                new_lcs = max(get_lcs(a_idx - 1, b_idx), get_lcs(a_idx, b_idx - 1))
            lcs_table[a_idx][b_idx] = new_lcs

    result = []
    current_a_idx = len(a) - 1
    current_b_idx = len(b) - 1
    while current_a_idx >= 0 and current_b_idx >= 0:
        if a[current_a_idx] == b[current_b_idx]:
            result.append(a[current_a_idx])
            current_a_idx -= 1
            current_b_idx -= 1
        else:
            if get_lcs(current_a_idx, current_b_idx) == 0:
                break
            if get_lcs(current_a_idx - 1, current_b_idx) > get_lcs(current_a_idx, current_b_idx - 1):
                current_a_idx -= 1
            else:
                current_b_idx -= 1

    return "".join(result[::-1])

inp = fileinput.FileInput()

a = inp.readline()
b = inp.readline()
print(lcs(a, b))

Measured memory_bytes: 113244
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpl;
typedef vector<tuple<int, int, int>> vti;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    
    int neg_cnt = 0;
    bool is_zero = false;
    rep(i, n){
        if (a[i] < 0){
            neg_cnt++;
            a[i] = - a[i];
        }
        if (a[i] == 0) is_zero = true;
    }
    ll ans = 0;
    rep(i, n) ans += a[i];
    
    if ((!is_zero) and (neg_cnt % 2 == 1)){
        int m = 1001001001;
        rep(i, n) m = min(m, a[i]);
        ans -= m * 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include  <stdio.h>

int main(){
    char a,b,c;
    scanf ("%c %c %c", &a,&b,&c);
    if (a==c&&a!=b){
    printf ("Yes\n");
    }
    else if (a==b&&a!=c){
    printf ("Yes\n");
    }
    else if (b==c&&a!=b){
    printf ("Yes\n");
    }
    else if (a==b&&a==c){
    printf ("No\n");
    }
    return 0;
}

Measured memory_bytes: 1620
#include<stdio.h>

int main(){
  int A[101];
  int B[101];
  
  int i,j,k;
  
  for(i=0;i<=101;i++){
    A[i]=B[i]=0;
  }
  
  int a,b,c,d;
  
  scanf("%d %d %d %d",&a,&b,&c,&d);
  
  for(i = a;i<b;i++)
    A[i]=1;
  for(i=c;i<d;i++)
    B[i]=1;
  
  int ans=0;
  
  for(i=0;i<101;i++){
    if(A[i] == 1 && B[i] == 1)
      ans++;
  }
  
  printf("%d\n",ans);
  return 0;
}
  


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

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def solve():
    s = input()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")

    return 0

if __name__ == "__main__":# {{{
    solve()

# vim: set foldmethod=marker: }}}


Measured memory_bytes: 75368
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0145
{
    public class Program

    {
        public static void Main(string[] args)
        {

            int n = RInt();
            int[][] ab = new int[n][];
            for (int i = 0 ; i < n ; i++)
            {
                ab[i] = RIntAr();
            }

            int[,] dp = new int[n, n];
            for (int i = 0 ; i < n ; i++)
            {
                for (int j = 0 ; j < n ; j++)
                {
                    dp[i, j] = (i == j) ? 0 : int.MaxValue;
                }
            }

            for (int k = 1 ; k < n ; k++)
            {
                for (int i = 0 ; i + k < n ; i++)
                {
                    int j = i + k;

                    for (int m = i ; m < j ; m++)
                    {
                        int tmp = dp[i, m] + dp[m + 1, j] + ab[i][0] * ab[m][1] * ab[m + 1][0] * ab[j][1];
                        dp[i, j] = Math.Min(dp[i, j], tmp);
                    }
                }
            }

            Console.WriteLine(dp[0, n - 1].ToString());
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 15932
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, q) = (v[0], v[1]);
    let mut uft = UnionFindTree::new(n);
    for i in 0..q {
        let v = read_vec::<usize>();
        let (s, u, v) = (v[0], v[1], v[2]);
        if s == 0 {
            uft.unite(u, v);
        } else {
            if uft.same(u, v) {
                println!("1");
            } else {
                println!("0");
            }
        }
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[derive(Debug, Clone)]
struct UnionFindTree {
    parent: Vec<isize>,
    size: Vec<usize>,
    height: Vec<u64>,
}

impl UnionFindTree {
    fn new(n: usize) -> UnionFindTree {
        UnionFindTree {
            parent: vec![-1; n],
            size: vec![1usize; n],
            height: vec![0u64; n],
        }
    }

    fn find(&mut self, index: usize) -> usize {
        if self.parent[index] == -1 {
            return index;
        }
        let idx = self.parent[index] as usize;
        let ret = self.find(idx);
        self.parent[index] = ret as isize;
        ret
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }

    fn get_size(&mut self, x: usize) -> usize {
        let idx = self.find(x);
        self.size[idx]
    }

    fn unite(&mut self, index0: usize, index1: usize) -> bool {
        let a = self.find(index0);
        let b = self.find(index1);
        if a == b {
            false
        } else {
            if self.height[a] > self.height[b] {
                self.parent[b] = a as isize;
                self.size[a] += self.size[b];
            } else if self.height[a] < self.height[b] {
                self.parent[a] = b as isize;
                self.size[b] += self.size[a];
            } else {
                self.parent[b] = a as isize;
                self.size[a] += self.size[b];
                self.height[a] += 1;
            }
            true
        }
    }
}


Measured memory_bytes: 6504