akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
#define mod 1000000007
#define mod2 998244353
#define double long double
#define pb push_back
#define swap(x,y) (x^=y^=x^=y)
#define TC int TESTCASE;cin>>TESTCASE;while(TESTCASE--)
#define oo 1500000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;
using namespace std;
 
bool isPrime(int n){
    if(n < 2)return 0;
    if(n < 4)return 1;
    if(n % 2 == 0 or n % 3 == 0)return 0;
    for(int i = 5; i*i <= n; i += 6)if(n % i == 0 or n % (i+2) == 0)return 0;
    return 1;
}
 
int modexpo(int x,int p){
    int res = 1;x = x%mod;
    while(p){
        if(p%2)res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}
 
int max(int a,int b){return (a>b?a:b);}
 
int min(int a,int b){return (a<b?a:b);}
 
struct edge{int u,v,w;edge(int a,int b,int c){u=a;v=b;w=c;}};
 
struct compare{
    bool operator() (const edge a, const edge b) const{
        if(a.u == b.u){
            if(a.v == b.v){
                return a.w < b.w;
            }
            return a.v < b.v;
        }
        return a.u < b.u;
    }
};


int32_t main(){
    IOS
    int n;
    cin >> n;
    vector<pair<int,int>>v;
    for(int i=1;i<n;i++){
        int a,b;
        cin >> a >> b;
        v.pb({min(a,b),max(a,b)});
    }
    sort(v.begin(),v.end());
    int dp[n];
    for(int i=0;i<n;i++){
        dp[i] = i+1;
    }
    for(int i=1;i<n;i++){
        dp[i] += dp[i-1];
    }
    for(int i=1;i<n;i++){
        dp[i] += dp[i-1];
    }
    int res = 0;
    for(int i=0;i<v.size();i++){
        //cout<<v[i].first<<" "<<v[i].second<<endl;
        res += (v[i].first)*(n - v[i].second+1);
    }
    //cout<<dp[n-1]<<endl;
    cout<<dp[n-1] - res<<endl;
} 

Measured memory_bytes: 8188
import sys
input = sys.stdin.readline

def func(people_num, train_fee, cab_fee):
    train = people_num*train_fee
    print(min(train, cab_fee))
    pass


def main():
    n, a, b = [int(i) for i in input().split()] 
    func(n,a,b)
    
# main関数呼び出し
if __name__ == "__main__":
    main() 

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

template <class T>
inline void read(T &x)
{
	static char ch; 
	static bool opt; 
	while (!isdigit(ch = getchar()) && ch != '-'); 
	x = (opt = ch == '-') ? 0 : ch - '0'; 
	while (isdigit(ch = getchar()))
		x = x * 10 + ch - '0'; 
	if (opt)
		x = ~x + 1; 
}

template <class T>
inline void putint(T x)
{
	static char buf[45], *tail = buf; 
	if (!x)
		putchar('0'); 
	else
	{
		if (x < 0)
			putchar('-'), x = ~x + 1; 
		for (; x; x /= 10) *++tail = x % 10 + '0'; 
		for (; tail != buf; --tail) putchar(*tail); 
	}
}

template <class T>
inline bool tense(T &x, const T &y)
{
	return y < x ? x = y, true : false; 
}

template <class T>
inline bool relax(T &x, const T &y)
{
	return x < y ? x = y, true : false; 
}

using std::min; 
using std::max; 
using std::pair; 
using std::cin; 
using std::cout; 
using std::vector; 
typedef long long s64; 
typedef __int128 s128; 
typedef long double ld; 
typedef std::pair<int, int> pii; 
#define mp(x, y) std::make_pair(x, y)

const int MaxN = 66; 
const int MaxM = 2e4 + 5; 

s64 n, a, b, c, d; 
std::map<s64, s128> f; 

inline s128 solve(s64 n)
{
	if (f.find(n) != f.end())
		return f[n]; 

	s128 res = (s128)d * n; 

	if (n >= 2)
		tense(res, solve(n / 2) + (n % 2) * d + a); 
	if (n % 2)
		tense(res, solve(n / 2 + 1) + d + a); 

	if (n >= 3)
		tense(res, solve(n / 3) + (n % 3) * d + b); 
	if (n % 3)
		tense(res, solve(n / 3 + 1) + (3 - n % 3) * d + b); 

	if (n >= 5)
		tense(res, solve(n / 5) + (n % 5) * d + c); 
	if (n % 5)
		tense(res, solve(n / 5 + 1) + (5 - n % 5) * d + c); 

	// std::cout << n << ':' << (s64)res << '\n'; 

	return f[n] = res; 
}

inline void work()
{
	f.clear(); 
	std::cin >> n >> a >> b >> c >> d; 

	f[1] = d; 
	putint(solve(n)); 
	putchar('\n'); 
}

int main()
{
	int T; 
	read(T); 

	while (T--)
		work(); 
	return 0; 
}

Measured memory_bytes: 4680
N = int(input())						# 5

A = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
B = [int(i) for i in input().split()]	# 1 2 3 4 5 ...


#print(N)
#print(A)
#print(B)


x=0
ans=0
for i in range(N):
	x = 0
	for k in range(N):
		if k<=i:
			x += A[k]
			#print("a", A[k])
		if k>=i:
			x += B[k]
			#print("b", B[k])
	ans = max(ans, x)
	#print("i=", i, "k=", k, "x=", x)


print(ans)


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
 
int main(){
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int count=0;
    for(int i=0;i<=a;i++){
      for(int j=0;j<=b;j++){
        for(int k=0;k<=c;k++){
          if(500*i+100*j+k*50==x)count++;
        }
      }
    }
    cout<<count;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int r; cin >> r;

  string ans = r < 1200 ? "ABC"
    : r < 2800 ? "ARC"
    : "AGC";

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
from sys import stdin
N,L=list(map(int,stdin.readline().strip().split()))
taste=L-1
apple_list=[]
min=3000
j=0
for i in range(1,N+1):
    apple_list.append(taste+i)
    if min>abs(taste+i):
        min=abs(taste+i)
        j=i-1
apple=sum(apple_list)
print(apple-(apple_list[j]))

Measured memory_bytes: 3064
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.nextLine();
        String b = sc.nextLine();
        int flag = 0;
        
        for (int i=0; i<a.length(); i++) {
            StringBuilder sb = new StringBuilder();
            for (int j=i; j<a.length(); j++) {
                sb.append(a.charAt(j));
            } 
            for (int j=0; j<i; j++) {
                sb.append(a.charAt(j));
            }
            if (sb.toString().equals(b)) {
                flag = 1;
                break;
            }
            
        }
        if (flag==1) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef long long lint;

int main(){
    int n; cin >> n;
    map<int, int> plc;
    int a[n];
    rep(i, n){
        cin >> a[i];
        plc[a[i]] = i;
    }
    sort(a, a+n);
    int cnt = 0;
    rep(i, n)if(i%2 != plc[a[i]]%2) cnt++;
    cout << cnt / 2 << endl;
}

Measured memory_bytes: 5376
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 *
	 */
	Scanner sc = new Scanner(System.in);

	void run() {
		char[] cs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
				.toCharArray();

		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			int[] ks = new int[n];
			for (int i = 0; i < n; i++) {
				ks[i] = sc.nextInt();
			}
			char[] list = sc.next().toCharArray();
			char[] ans = new char[list.length];
			int kidx = 0;
			for (int i = 0; i < list.length; i++) {
				int idx = 0;
				if (list[i] >= 'A' && list[i] <='Z') {
					idx = list[i] - 'A' + 26;
				} else {
					idx = list[i] - 'a';
				}
				int nidx = (idx - ks[kidx] + 52) % 52;
				if (nidx >= 26) {
					ans[i] = (char) ('A' + nidx - 26);
				} else {

					ans[i] = (char) ('a' + nidx);
				}

				kidx += 1;
				kidx %= n;
			}

			System.out.println(new String(ans));
		}

	}

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().run();

	}

}

Measured memory_bytes: 24888
from collections import Counter

n = int(input())
p = [int(input()) for _ in range(n)]

lst = [False] * (n + 1)
for num in p:
    bfo = lst[num - 1]
    if bfo:
        lst[num] = bfo
    else:
        lst[num] = num
cnt = Counter(lst).values()
print(n - max(cnt))


Measured memory_bytes: 135008
#include <stdio.h>

int sumd (int num){
     int sum = 0;
     while (num != 0){
        sum += num % 10;
        num /= 10;
     }
    return sum;

}
int main (){
int a ,b,c ,i,tmp,sum=0 ;
scanf ("%d%d%d",&a,&b,&c);

for (i = 1 ; i <=a ;i++ ){
    tmp = sumd(i);
    if (tmp >= b && tmp <= c  )
      sum += i;
    }
printf("%d\n",sum);

return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    int n, k;
    cin >> n >> k;
    int h[n + 1];
    rep(i, n) cin >> h[i];
    int dp[n + 1];

    rep(i, n) dp[i] = 1e9;

    dp[0] = 0;

    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            if (i - j >= 0)
                dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }

    OP(dp[n - 1]);
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
#include<list>
using namespace std;

int main() {

	string S;
	cin >> S;

	int ans = 0;
	for (int i = 0; i < S.length(); i++) {
		if (S[i] == '+') {
			ans += 1;
		}
		else {
			ans -= 1;
		}
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll i,j,k,m,n,t;
	cin>>n;
	vector<pair<ll,ll>> v;
	ll ctr=0;
	ll mx=0;
	for(i=0;i<n;i++)
	{
		cin>>j>>k;
		v.push_back({j,k});
	}
	bool fl=false;
	for(i=0;i<n-2;i++)
	{
		if(v[i].first==v[i].second and v[i+1].first==v[i+1].second and v[i+2].first==v[i+2].second)
		fl=true;
	}
	if(fl)
	cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
    using namespace std;
 
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define mod 1000000007
    #define qmod 998244353
    #define M 1000001
    #define endl "\n"
    #define all(a) (a).begin(),(a).end()
    #define rep(i,a,b) for(int i=a;i<b;++i)
    #define repr(i,a,b) for(int i=a;i>=b;--i)
    #define F first
    #define S second
    #define pb push_back
    #define mp make_pair
 
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef vector<int> vi;
    typedef vector<string> vs;
    typedef vector<pii> vii;
    typedef vector<vi> vvi;

    int main(){
                    
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin); 
    freopen("output.txt","w",stdout);   
    #endif 
 
        fast;
        int t=1; 
        // cin>>t; 
        while(t--){
            string s,t;
            cin>>s>>t;
            t.pop_back();
            cout<<(s==t?"Yes":"No");
        } 
        return 0;   
    }       


    //keep it simple stupid 

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

using namespace std;

set<int>g[26];

int main(){
	string s,t;
	cin>>s>>t;
	for(int i=0;i<(int)s.size();++i){
		g[s[i]-'a'].insert(i+1);
	}
	long long cur=0,ans=0;
	for(int i=0;i<(int)t.size();++i){
		if((int)g[t[i]-'a'].size()==0){
			cout<<-1;
			return 0;
		}
		if(g[t[i]-'a'].upper_bound(cur)!=g[t[i]-'a'].end()){
			cur=*g[t[i]-'a'].upper_bound(cur);
		}
		else{
			cur=*g[t[i]-'a'].upper_bound(0);
			ans+=(int)s.size();
		}
		//cerr<<cur<<' '<<ans<<'\n';
	}
	cout<<ans+cur;
}

Measured memory_bytes: 8540
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
	double a, l, x;
	while (cin >> a >> l >> x) {
		double h_1 = sqrt(l * l - (a/2) * (a/2));
		double m = a * h_1 / 2;
		double h_2 = sqrt(((x + l)/2)* ((x + l)/2) - (l/2) * (l/2));
		double s = l * h_2 / 2;
		printf("%.6f\n", m + s * 2);
	}

	return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
int freq[1001];
using namespace std ; 

int exist[10000001], divid[10000001];

int main (){
int n ;
cin>>n;
int Num[n];
  for(int i =0;i<n;i++){
    cin>>Num[i];
    exist[Num[i]]++;

  }
if(exist[1]){
  if(exist[1]>1)cout<<0; 
  else 
   cout<<1; 
}else{
  for(int i =2;i<n;i++){
    for(int j =Num[i]*2;j<=1000000;j+=Num[i]){
      if(exist[j])divid[j]++;
    }
    if(exist[Num[i]]>1)divid[Num[i]]++;
  }int c=0;
  for(int i =0;i<=10000001;i++){
    if(exist[i] and divid[i]){
     
      c+=exist[i];
    }
  }cout<<n-c;
  return 0;
}}

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

using namespace std;

const int MAX_N = 55;

long long dp[2][MAX_N*MAX_N][MAX_N],ans;

int main()
{
	int n,a,x;
	cin >> n >> a;
	dp[0][0][0]=dp[1][0][0]=1;
	for (int i=1; i<=n; i++)
	{
		cin >> x;
		copy(&dp[(i+1)&1][0][1],&dp[(i+1)&1][n*a][n]+1,
				&dp[i&1][0][1]);
		for (int k=1; k<=n; k++)	
			for (int s=x; s<=n*a; s++)
				dp[i&1][s][k]+=dp[(i+1)&1][s-x][k-1];
	
//		copy(&dp[1][0][1],&dp[1][n*a][n]+1,&dp[0][0][1]);
//		transform(&dp[0][x][1],&dp[0][n*a][n]+1,&dp[1][0][0],&dp[0][x][1],plus<>());
//		swap(dp[0],dp[1]);
	}
	for (int k=1; k<=n; k++)
		ans+=dp[n&1][a*k][k];
	cout << ans;
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int cnt = 0;
    rep(i, a+1) rep(j, b+1) {
        int remain = x - 500 * i - 100 * j;
        int k = remain / 50;
        if (remain % 50 == 0 && 0 <= k && k <= c) {
            cnt++;
        }
    }
    put(cnt)
    return 0;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define MOD (ll)1000000007

int main(void)
{
	ll x, k, d;
	scanf("%lld %lld %lld", &x, &k, &d);
	ll temp = (abs(x) - 1LL) / d + 1LL;
	if (k >= temp)
	{
		if (x < 0)
		{
			ll ans = x + temp * d;
			if ((k - temp) % 2)
				printf("%lld", min(abs(ans - d), abs(ans + d)));
			else
				printf("%lld", abs(ans));
		}
		else
		{
			ll ans = x - temp * d;
			if ((k - temp) % 2)
				printf("%lld", min(abs(ans - d), abs(ans + d)));
			else
				printf("%lld", abs(ans));
		}
	}
	else
	{
		if (x < 0)
			printf("%lld", abs(x + k * d));
		else
			printf("%lld", abs(x - k * d));
	}

	return 0;
}

Measured memory_bytes: 1732
import sys
sys.setrecursionlimit(10**6)

def dfs(n):
    if n > 3234566667:
        return
    ans.append(n)
    if n % 10 != 0:
        dfs(n * 10 + (n % 10) - 1)
    dfs(n * 10 + (n % 10))
    if n % 10 != 9:
        dfs(n * 10 + (n % 10) + 1)

N = int(input())
ans = []
for i in range(1, 10):
    dfs(i)
ans.sort()
print(ans[N - 1])

Measured memory_bytes: 7644
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    string S, T;
    cin >> N >> M >> S >> T;
    ll g = gcd(N, M);
    ll ans = N / g * M;
    N /= g, M /= g;
    bool ok = true;
    REP(i,g){
        if(S[i*N] != T[i*M]) ok = false;
    }
    if(ok) cout << ans << endl;
    else cout << -1 << endl;
}

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

using namespace std;

const int N = 100000 + 7;

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

  multiset<int> num; num.clear();
  while(l <= r) {
    if(num.count(l % 2019) < 2) num.insert(l % 2019);
    else break;
    ++l;
  }

  int ans = 2019;
  for(int i: num) {
    for(int j: num) {
      if(i != j) {
        ans = min(ans, (i * j) % 2019);
      }
    }
  }

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    for(int i=0;i<a.size();i++){
        if(a.size()<4){
            cout<<"No"<<endl;
            return 0;
        }
        else if(a[0]=='Y'&&a[1]=='A'&&a[2]=='K'&&a[3]=='I'){
            cout<<"Yes"<<endl;
            return 0;
        }
        else{
            cout<<"No"<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
n = int(input())
x = list(map(int,input().split()))
y =[]
for i in range(n):
    y.append([x[i],i])
y.sort(key = lambda x:x[0])
ans1 =y[n//2][0]
ans2 =y[n//2-1][0]
#print(ans1,ans2)
for i in x:
    if i <=ans2:
        print(ans1)
    else:
        print(ans2)

Measured memory_bytes: 43840
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define PI 3.14159265
#define pb push_back
#define pr pair<int,int>
using namespace std;
using ll = long long;
// using mod = 1000000000 + 7;
void self_max(int &a,int b){
	a = max(a,b);
}

void self_min(int &a,int b){
	a = min(a,b);
}
int main(){
	ll n; cin >> n;
	string ans = "";

	while(n){
		n--;
		ans += ('a' + n%26);
		n/=26;
	}

	reverse(ans.begin(),ans.end());
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
/*
    By: Umang Srivastava
*/
#define lli long long int
#define ld long double
#define mod 1000000007
#define lp(var,start,end,inc) for (var = start; var <end ; var=var+inc)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<lli>
#define pll pair<lli,lli> 
#define vpll vector<plli>
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b


// lli findgcd(lli a, lli b, lli *x , lli *y)
// {
//     if(a==0)
//     {
//         *x=0,*y=1;
//         return b;
//     }
//     lli x1,y1;
//     lli gcd = findgcd(b%a,a,&x1,&y1);
//     *x=y1-(b/a)*x1;
//     *y=x1;
//     return gcd;
// }

// lli modInv(lli b)
// {
//     lli x,y;
//     lli g = findgcd(b,mod,&x,&y);
//     if(g!=1)
//         return -1;
//     return (x%mod + mod)%mod;
// }

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli n,s=0,i,s2=0,ans;
    cin>>n;
    lli ar[n];
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
        s= (s + ar[i])%mod;
        s2 = (s2%mod + (ar[i]*ar[i])%mod)%mod;
    }
    s=((s%mod)*(s%mod))%mod;

    s=((s-s2)%mod+mod)%mod;
    lli inv = 500000004;

    ans=(s*inv)%mod;
    cout<<ans;

}

Measured memory_bytes: 5232
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

/* ユークリッドの互除法 最大公約数*/
ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}



/*最小公倍数*/
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}

/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}

//小数点9桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll n,t=0,ans=LLONG_MAX;
    cin>>n;
    vector<ll>a(n);
    vector<ll>s(n+1,0);
    sort(a.begin(),a.end());
    for(ll i=0;i<n;i++){
        cin>>a[i];
        t+=a[i];
        s[i+1]=t;
    }
    for(ll i=1;i<n;i++){
        ans=min(abs((s[n]-s[i])-s[i]),ans);
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;

    


    
    
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
double PI = acos(-1); 
long long MOD = 998244353; 
long long fac[100010], finv[100010], inv[100010]; 
void COMinit(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i = 2; i < 100005; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(int n, int k){
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
	int N; cin >> N; 
	int H[100010] = {}; 
	long long P[50010] = {}; 
	P[0] = 1; 
	COMinit(); 
	for(int i = 1; i < 50005; i++) P[i] = P[i-1] * (i*2-1) % MOD; 
	for(int i = 0; i < N * 2; i++){
		int h; cin >> h; H[h] ++; 
	}
	priority_queue<pair<int, vector<long long>>> S; 
	vector<long long> w = {1}; 
	S.push(make_pair(-1, w)); 
	S.push(make_pair(-1, w)); 
	for(int i = 1; i <= 100000; i++){
		if(H[i] >= 2){
			vector<long long> V(H[i] / 2 + 1);
			for(int t = 0; t <= H[i] / 2; t++){
				V[t] = COM(H[i], t*2) * P[t] % MOD; 
			}
			S.push(make_pair(- H[i] / 2 - 1, V)); 
		}
	}
	while(S.size() >= 2){
		auto s = S.top(); S.pop(); 
		auto t = S.top(); S.pop();
		vector<long long> u = convolution(s.second, t.second); 
		auto w = make_pair((int) u.size() * (-1), u); 
		S.push(w); 
	}
	auto s = S.top(); 
	long long ans = 0; 
	for(int i = 0; i < - s.first; i++){
		long long c = (s.second).at(i) % MOD; 
		c *= P[N - i]; c %= MOD; 
		if(i % 2) c *= -1; 
		ans += c; 
		ans += MOD; ans %= MOD; 
	}
	cout << ans << "\n"; 
}

Measured memory_bytes: 9128
#include <iostream>

using namespace std;

int main(){
  #define MMM 100
  int num_count[MMM] = {0};
  int num;
  int mode_value=0;

  while(cin >> num){
    num_count[num]++;
    if(num_count[num] > mode_value){
      mode_value++;
    }
  }
  
  for(int i=0;i<MMM;i++){
    if(num_count[i] == mode_value){
      cout << i << endl;
    }
  }
}

Measured memory_bytes: 0
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

vector<int> a;

int Partition(int p, int r) {
	int x = a[r];
	int i = p - 1;
	for (int j = p; j < r; j++) {
		if (a[j] <= x) {
			i++;
			swap(a[i], a[j]);
		}
	}
	swap(a[i + 1], a[r]);
	return i + 1;
}

int main() {
	int n;
	cin >> n;
	a.resize(n);
	REP(i, n)cin >> a[i];
	int idx = Partition(0, n - 1);
	REP(i, n) {
		if (i)cout << " ";
		if (i == idx)cout << "[";
		cout << a[i];
		if (i == idx)cout << "]";
	}
	cout << endl;
}


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

namespace Contest
{
    partial class Program
    {
        static void Main(string[] args)
        {
            ABC155_A();
        }

        static void ABC155_A()
        {
            var abc = ReadIntN();
            var A = abc[0];
            var B = abc[1];
            var C = abc[2];
            if (A == B && B == C) { Console.WriteLine("No");return; }
            if (A == B || A == C || B == C) { Console.WriteLine("Yes");return; }
            Console.WriteLine("No");
        }
        static void ABC155_B()
        {

        }
        static void ABC155_C()
        {

        }
        static void ABC155_D()
        {

        }
        static void ABC155_E()
        {

        }
        static void ABC155_F()
        {

        }

        static string ReadStr()
        {
            return Console.ReadLine();
        }
        static string[] ReadStrN()
        {
            return Console.ReadLine().Split(' ');
        }
        static int ReadInt()
        {
            return Convert.ToInt32(Console.ReadLine());
        }
        static int[] ReadIntN()
        {
            return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
        }
        static long ReadLong()
        {
            return Convert.ToInt64(Console.ReadLine());
        }
        static long[] ReadLongN()
        {
            return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
        }
        static Tuple<long, long>[]  ReadTupleLong(int n)
        {
            List<Tuple<long, long>> list = new List<Tuple<long, long>>();
            for (int i = 0; i < n; ++i)
            {
                var ab = ReadLongN();
                list.Add(new Tuple<long, long>(ab[0], ab[1]));
            }
            return list.ToArray();
        }
    }
}


Measured memory_bytes: 11348
N, M = map(int, input().split())
K = []
S = []
for m in range(M):
    l = list(map(int, input().split()))
    k = l.pop(0)
    K.append(k)
    S.append(l)
P = list(map(int, input().split()))
ans = 0
for n in range(1<<N):
    res = True
    for m in range(M):
        cnt = 0
        for q in range(K[m]):
            if n & (1<<S[m][q]-1):
                cnt += 1
        if cnt % 2 != P[m]:
            res = False
    if res:
        ans += 1
print(ans)


Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
//#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  vector<int> vec(9, 0);
  
  rep(i, N) {
    int a; cin >> a;
    if(1 <= a && a <= 399) vec[0]++;
    else if(a <= 799) vec[1]++;
    else if(a <= 1199) vec[2]++;
    else if(a <= 1599) vec[3]++;
    else if(a <= 1999) vec[4]++;
    else if(a <= 2399) vec[5]++;
    else if(a <= 2799) vec[6]++;
    else if(a <= 3199) vec[7]++;
    else vec[8]++;
  }
  
  int ans = 0;
  rep(i, 8) if(vec[i] > 0) ans++;
  if(ans == 0) cout << min(1, vec[8]) <<" ";
  else cout << ans << " ";
  cout  << ans+vec[8] << endl;
  
  

}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <cstdio>
#include <list>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecstr vector<string>
#define vecch vector<char>
#define vecpii vector<pii>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
string strin(){string s;cin>>s;return s;}
char chin(){char c;cin>>c;return c;}
ll lin() {ll x;scanf("%lld",&x);return x;}

int main(){
    int n=in(),m=in();
    ll mod=1000000007;
    vector<int>a(n+1),b(m+1);
    a[n]=0;b[m]=0;
    rep(i,n)a[i]=in();sort(All(a),greater<int>());
    rep(i,m)b[i]=in();sort(All(b),greater<int>());
    int p=0,q=0;
    ll ans=1;
    rep3(k,n*m,1){
        if(a[p]>k||b[q]>k){
          ans=0;
          break;
        }
        else if(a[p]==k&b[q]<k){
            ans*=q;
            p++;
        }else if(a[p]<k&b[q]==k){
            ans*=p;
            q++;
        }else if(a[p]<k&b[q]<k) ans*=p*q-n*m+k;
        else{
            p++;
            q++;
        }
        ans%=mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	char a;
	
	cin >> a;
	if(a == 'a' || a == 'o' || a == 'u' || a == 'e' || a == 'i'){
		cout << "vowel";
		return 0;
	}
	
	cout << "consonant";
	return 0;
}


Measured memory_bytes: 3644
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll r = inl(), d = inl(), x = inl();
        ll cur = x;
        rep(i, 10) {
            cur = cur * r - d;
            cout << cur << endl;
        }

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
const int INF = 1 << 20;

typedef long long ll;




int main(){
  ll n;
  vector <ll> a;
  cin >> n;
  a.pb(0);
  REP(i,n){

    ll b;
    cin >> b;
    a.pb(b);
  }
  ll sum = 0;
  REP(i,a.size()-1){
    sum += abs(a[i]-a[i+1]);
  }
  sum += abs(a[0]-a[a.size()-1]);

  //cout << sum << endl;
  ll res = 0;
  res = sum - abs(a[0]-a[1]) - abs(a[0]-a[a.size()-1]) + abs(a[1]-a[a.size()-1]);
  //cout << res << endl;
  for(int i = 1;i < a.size()-1;i++){

    res = sum - abs(a[i]-a[i-1]) - abs(a[i]-a[i+1]) + abs(a[i+1]-a[i-1]);
    cout << res << endl;
  }
  res = sum - abs(a[a.size()-1]-a[a.size()-2]) - abs(a[a.size()-1]-a[0])+abs(a[a.size()-2]-a[0]);
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;

  if (s[0] == s[1] && s[1] == s[2]) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
n,m=gets.split.map &:to_i
p=[];y=[]
m.times{|i|p[i],y[i]=gets.split.map &:to_i}
ans=p.zip(y,(0..m).to_a).sort_by{|x|[x[0],x[1]]}
z=1
for i in 0...m
  (ans[i][3]=z;next) if i==0
  if ans[i-1][0]==ans[i][0]
    z+=1
    ans[i][3]=z
  else
    z=1
    ans[i][3]=z
  end
end
m.times{|i|
    x=(1000000+ans[i][0]).to_s.chars
    y=(1000000+ans[i][3]).to_s.chars
    x.shift;y.shift
    ans[i][4]=(x+y).join
}
ans=ans.sort_by{|x|x[2]}
ans.each{|y|puts y[4]}


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

long long dp[100005], dp2[100005], otg;
int A[100005], B[100005], C[100005];
int main(){

int n;
cin>>n;
for(int i=0;i<n;i++)
    cin>>A[i];
for(int i=0;i<n;i++)
    cin>>B[i];
for(int i=0;i<n;i++)
    cin>>C[i];
sort(A,A+n);
sort(B,B+n);
sort(C,C+n);
int curr=0;
for(int i=0;i<n;i++)
{
    if(i>0)
        dp[i]=dp[i-1];
    while(A[curr]<B[i] && curr<n)
    {
        curr++;
        dp[i]++;
    }
}

//for(int i=0;i<n;i++)
  //  cout<<dp[i]<<" ";
curr=n-1;
for(int i=n-1;i>=0;i--)
{
    if(i<n-1)
        dp2[i]=dp2[i+1];
    while(C[curr]>B[i] && curr>=0)
    {
        curr--;
        dp2[i]++;
    }
}
for(int i=0;i<n;i++)
{
    otg+=dp[i]*dp2[i];
}
cout<<otg<<endl;
return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main()
{
    int a, b;
    cin >> a >> b;
    cout << max(max(a+b, a-b), a*b);
}

Measured memory_bytes: 256
import sys
n = int(input())
p_t = 0
p_h = 0

for i in range(n):
	taro, hanako = input().split()
	if taro == hanako:
		p_t += 1
		p_h += 1
	else:
		l_t = list(taro)
		l_h = list(hanako)
		for j in range(min(len(l_t), len(l_h))):
			if l_t[j] != l_h[j]:
				if ord(l_t[j])<ord(l_h[j]):
					p_h += 3
					#print('taro')
					break
				else:
					p_t += 3
					#print('hanako')
					break
			else:
				if j == min(len(l_t), len(l_h))-1:
					if len(l_t)>len(l_h):
						p_t += 3
					else:
						p_h += 3
					

print(p_t, p_h)

Measured memory_bytes: 7664
# -*- coding: utf-8 -*-
"""
Created on Sun Aug  5 19:16:30 2018
ABC104B
@author: maezawa
"""

s = input()

flag = 0
if s[0] == 'A':
    if s.count('C', 2, -1) == 1:
        s1 = s[1:]
        s2 = s1.replace('C', 'c')
        if s2.islower():
            print('AC')
            flag = 1

if flag == 0:
    print('WA')

Measured memory_bytes: 3060
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#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>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

struct order {
	string name;
	char com;
	int price;
	bool operator < (const order &a) const {
		return price < a.price;
	}
};

struct comodity {
	int min, max, sum, cnt;
};

void addCom(map<char, comodity> &m, int v, char name) {
	if(!m.count(name)) {
		comodity c;
		c.min = c.max = c.sum = v;
		c.cnt = 1;
		m[name] = c;
	}
	else {
		m[name].min = min(m[name].min, v);
		m[name].max = max(m[name].max, v);
		m[name].sum += v;
		m[name].cnt++;
	}
}

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

	int n;
	while(cin >> n, n) {
		vector<order> buy, sell;
		map<string, pi> ppl;
		map<char, comodity> m;
		REP(i, n) {
			order o; string in;
			cin >> o.name >> in >> o.com >> o.price;
			if(!ppl.count(o.name))
				ppl[o.name] = mp(0,0);

			bool flg = false;
			int v, pnt;
			if(in == "SELL") {
				REP(j, buy.size()) {
					if(o.com == buy[j].com && o.name != buy[j].name && o.price <= buy[j].price) {
						v = (o.price + buy[j].price) / 2;
						addCom(m, v, o.com);
						flg = true;
						pnt = j;
						break;
					}
				}
				if(flg) {
					ppl[buy[pnt].name].first += v;
					ppl[o.name].second += v;
					buy.erase(buy.begin() + pnt);
				}
				else {
					sell.pb(o);
					stable_sort(sell.begin(), sell.end());
				}
			}
			else if(in == "BUY") {
				REP(j, sell.size()) {
					if(o.com == sell[j].com && o.name != sell[j].name && o.price >= sell[j].price) {
						v = (o.price + sell[j].price) / 2;
						addCom(m, v, o.com);
						flg = true;
						pnt = j;
						break;
					}
				}
				if(flg) {
					ppl[o.name].first += v;
					ppl[sell[pnt].name].second += v;
					sell.erase(sell.begin() + pnt);
				}
				else {
					buy.pb(o);
					stable_sort(buy.rbegin(), buy.rend());
				}
			}
		}
		for(auto i : m)
			cout << i.first << ' ' << i.second.min << ' ' << i.second.sum / i.second.cnt << ' ' << i.second.max << endl;
		cout << "--" << endl;
		for(auto i : ppl)
			cout << i.first << ' ' << i.second.first << ' ' << i.second.second << endl;
		cout << "----------" << endl;
	}
	return 0;
}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 998244353
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main(){
    ll n, x, m;
    cin >> n >> x >> m;
    vi id(m, -1);
    vi a;
    int len = 0;
    ll total = 0;
    while(id[x] == -1){
        a.push_back(x);
        id[x] = len;
        len++;
        total += x;
        x = (x*x) % m;
    }

    int roop = len - id[x];
    ll s = 0;
    for(int i = id[x]; i < len; i++) s += a[i];

    ll ans = 0;
    if(n <= len){
        rep(i, n) ans += a[i];
    }else{
        ans += total;
        n -= len;
        ans += s*(n/roop);
        n %= roop;
        rep(i, n) ans += a[id[x] + i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		String s = scan.next();
		String t = scan.next();

		String S;
		String T;
		int cnt=0;
		for(int i=0;i<N;i++){
			S = s.substring(i,N);
			T = t.substring(0,N-i);
			if(S.equals(T)){
				cnt = N-i;
				break;
		}
		}

		System.out.println(2*N-cnt);


		}

}
//7'03'

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

int main(int argc, char** argv) {
  bool is_odd  = true;
  bool is_even = true;
  std::string S;
  std::cin >> S;
  int S_size = S.size();
  for (auto i = 0;i < S_size;++i) {
    if (i % 2 == 0) {
      if (S[i] == 'R' || S[i] == 'U' || S[i] == 'D') {
      } else {
        is_even = false;
      }
    } else {
      if (S[i] == 'L' || S[i] == 'U' || S[i] == 'D') {
      } else {
        is_odd = false;
      }
    }
  }
  if (is_odd && is_even) std::cout << "Yes\n";
  else std::cout << "No\n";
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
if sum(a)==0:
    print(0)
    exit()
else:
    k=0
    s=sum(a)
    for i in range(n-1):
        s-=a[i]
        s1=s%(10**9+7)
        k+=(s1*a[i])%(10**9+7)
print(k%(10**9+7))

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  auto temp=0, max_ans=0;
  for(auto i:s){
    if(i=='I') temp++;
    if(i=='D') temp--;
    max_ans = max(max_ans,temp);
  }
  cout << max_ans << endl;

  return 0;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int ans=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i] == '-')
			ans--;
		if(s[i] == '+')
			ans++;
	}
	cout << ans;
	return 0;
} 	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    int n, a, b;
    cin >> n;
    while (n--) {
        cin >> a >> b;
        int ans = a % b;
        cout << (ans ? ans : b) << "\n";
    }
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e6+9;
int main()
{
    FASTINOUT;
    int x,y,c,d;
    cin>>x>>y>>c>>d;
    cout<<max(0,min(d,y)-max(x,c))<<endl;
    return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    long long t=1, a=1;
    cin >> n;
    for (int i=0; i<n; i++) {
        long long ti, ai;
        cin >> ti >> ai;
        long long k = max(t/ti+(t%ti==0?0:1), a/ai+(a%ai==0?0:1));
        t = ti * k;
        a = ai * k;
    }
    cout << t + a << endl;
}

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

using namespace std;

long long memo[2005][2005];

int S[100005];
int T[100005];

long long MOD = 1e9+7;

long long dp(int i, int j){
	if(i == 0 || j == 0){
		return 1;
	}else if(memo[i][j] != -1){
		return memo[i][j];
	}else{
		long long temp = dp(i-1, j) + dp(i, j-1);
		if(S[i-1] != T[j-1]){
			temp += MOD-dp(i-1, j-1);
		}
		return memo[i][j] = temp%MOD;
	}
}

int main(){
	int N, M;
	scanf("%d%d", &N, &M);
	
	for(int i = 0; i < N; i ++){
		scanf("%d", &S[i]);
	}
	
	for(int i = 0; i < M; i ++){
		scanf("%d", &T[i]);
	}
	
	memset(memo, -1, sizeof(memo));
	printf("%lld", dp(N, M));
	return 0;
}


Measured memory_bytes: 31872
def slove():
    import sys
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    t = 1
    cnt = 0
    while True:
        if t >= b:
            print(cnt)
            exit()
        else:
            t += a
            t -= 1
            cnt += 1


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <stdio.h>
#include <string.h>
#define MIN(a, b) ((a < b) ? a : b)

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

  char S[50][26];
  memset(S, 0, sizeof(char)*50*26);
  char M[26];
  memset(M, 100, sizeof(char)*26);
  for(int i = 0; i < n; i++) {
    char s[51];
    scanf("%s", s);
    for(int j = 0; s[j] != '\0'; j++) {
      S[i][s[j]-'a']++;
    }
    for(int j = 0; j < 26; j++) {
      M[j] = MIN(M[j], S[i][j]);
    }
  }
  
  for(int i = 0; i < 26; i++) {
    for(int j = 0; j < M[i]; j++) {
      printf("%c", i+'a');
    }
  }
  printf("\n");
  return 0;
}




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

using namespace std;
#define _for(i,j,N) for(int i = (j); i < (N);i++)
#define _rep(i,j,N) for(int i = (j); i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define LL long long

int get_int(){int x;scanf("%d",&x);return x;}
LL get_long(){LL x;scanf("%lld",&x);return x;}

int main()
{
    LL a,b;
    scanf("%lld %lld",&a,&b);
    LL gd = __gcd(a,b);
    if(b == gd) printf("%d\n",-1);
    else{
        printf("%lld\n",a);
    }

    return 0;
}


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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  string s, t; cin >> s >> t;
  rep(i, 101) {
    char c = s.back();
    s.pop_back();

    s = c + s;
    if (s == t) {
      cout << "Yes" << endl;
      return (0);
    }
  }

  cout << "No" << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> s(m);
    rep(i, m) {
        ll k;
        cin >> k;
        s[i].resize(k);
        rep(j, k) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    vector<ll> p(m);
    rep(i, m) cin >> p[i];
    ll ans = 0;
    rep(bit, 1 << n) {
        ll on = 0;
        rep(i, m) {
            ll cnt = 0;
            rep(j, sz(s[i])) {
                if ((bit & (1 << s[i][j])) != 0) cnt++;
            }
            if (cnt % 2 == p[i]) on++;
        }
        if (on == m) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256