akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
# import numpy as np
from fractions import gcd

sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)

n = inp()
s = str(n)
for i in range(3):
    if s[i] == '7':
        print('Yes')
        exit()
print('No')


Measured memory_bytes: 10964
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

template <typename T>
T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T>
T lcm(T m, T n) { return n * m / gcd(n, m); }

void primeFactorize(int n, vector<int> &v)
{
  v = vector<int>(n + 1, 0);
  int a = 2;
  while (n >= a * a)
  {
    if (n % a == 0)
    {
      ++v[a];
      n /= a;
    }
    else
    {
      a++;
    }
  }
  v[n]++;
}

signed main(void)
{
  int num;

  int a, b;
  cin >> a >> b;

  // vector<int> va;
  // vector<int> vb;
  // primeFactorize(a, va);
  // primeFactorize(b, vb);

  // num = 1;
  // vector<int> v(min(a, b) + 1, 0);
  // for (int i = 0; i < va.size(); ++i)
  // {
  //   cout << va[i] << " ";
  // }
  // cout << endl;
  // for (int i = 0; i < vb.size(); ++i)
  // {
  //   cout << vb[i] << " ";
  // }
  // cout << endl;
  // for (int i = 0; i < v.size(); ++i)
  // {
  //   v[i] = min(va[i], vb[i]);
  //   cout << v[i] << " ";
  //   if (v[i] > 0)
  //     ++num;
  // }
  // cout << endl;
  // cout << num << endl;

  num = 1;
  int n = min(sqrt(a), sqrt(b));
  for (int i = 2; i <= n; ++i)
  {
    int ca = 0;
    int cb = 0;
    while (a % i == 0)
    {
      a /= i;
      ++ca;
    }
    while (b % i == 0)
    {
      b /= i;
      ++cb;
    }
    if (ca > 0 && cb > 0)
    {
      ++num;
    }
  }

  if (a == b && a > n)
    ++num;
  cout << num << endl;

  // vector<int> v(min(sqrt(a), sqrt(b)) + 1, 0);
  // for (int i = 2; i < v.size(); ++i)
  // {
  //   int ca = 0;
  //   int cb = 0;
  //   while (a % i == 0)
  //   {
  //     a /= i;
  //     ++ca;
  //   }
  //   while (b % i == 0)
  //   {
  //     b /= i;
  //     ++cb;
  //   }
  //   if (ca > 0 && cb > 0)
  //   {
  //     ++num;
  //   }
  // }

  // cout << num << endl;

  // {
  //   num = 0;
  //   vector<int> v(min(sqrt(a), sqrt(b)) + 1, 0);
  //   for (int i = 2; i < v.size(); ++i)
  //   {
  //     int ca = 0;
  //     int cb = 0;
  //     while (a % i == 0)
  //     {
  //       a /= i;
  //       ++ca;
  //     }
  //     while (b % i == 0)
  //     {
  //       b /= i;
  //       ++cb;
  //     }
  //     if (ca > 0 && cb > 0)
  //     {
  //       ++num;
  //     }

  //     // if (a % i == 0)
  //     // {
  //     // }
  //     // if (b % i == 0)
  //     // {
  //     // }
  //     cout << num << endl;
  //   }
  // }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include "bits/stdc++.h"
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string s;
	int K;
	scan(s>>K);
	rep(i,s.size()){
		if(i!=s.size()-1){
			int toa=('z'-s[i]+1)%26;
			if(toa<=K){
				s[i]='a';
				K-=toa;
			}
		}
		else{
			int shift=s[i]-'a';
			shift+=K%26;
			if(shift>25) s[i]='a'+(shift-26);
			else s[i]='a'+shift;
		}
	}
	prin(s);
	return 0;
}


Measured memory_bytes: 512
#include<cstdio>
int main(){
    int n,x;
    while(~scanf("%d%d",&n,&x)){
        int ans=1;
        int tot=0;
        int l;
        for(int i=0;i<n;i++){
            scanf("%d",&l);
            tot+=l;
            if(tot<=x) ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
using namespace std;
const constexpr int INF = 1e9;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9 + 7;
const int BITSIZE = 100010;

struct Less {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.second < y.second;
	}
};
struct More {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.first > y.first;
	}
};
//1-indexed
int bit[100010];

int bit_query(int i) {
	int res = 0;
	for (; i >= 1; i -= i & -i) res = max(res, bit[i]);
	return res;
}

void bit_set(int x, int v) {
	for (; x <= BITSIZE; x += x & -x) {
		bit[x] = max(bit[x], v);
	}
}

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

	int cnt = 0, pre = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '(') {
			cnt++;
		}
		else {
			cnt--;
			pre = max(pre, -cnt);
		}
	}
	REP(i, pre) s = "(" + s;

	cnt = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '(') {
			cnt++;
		}
		else {
			cnt--;
		}
	}
	REP(i, cnt) s = s + ")";
	cout << s << endl;

	int aa; cin >> aa;
	return 0;
}

Measured memory_bytes: 256
import sys
(n, k) = list(map(int, input().split()))
mapa = {}
for _ in range(n):
    (a, b) = list(map(int, input().split()))
    if a in mapa:
        mapa[a] += b
    else:
        mapa[a] = b

mapa = sorted(mapa.items())
for i in mapa:
    if k <= i[1]:
        print(i[0])
        sys.exit(0)
    else:
        k -= i[1]

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

typedef long long ll;

const int MOD = 1e9 + 7;
const int INF = 0x3F3F3F3F;
const ll INFLL = 0x3F3F3F3F3F3F3F3FLL;

int main(){
	
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	vector<ll> v(n);
	for(int i = 0 ; i < n ; i ++)
		cin >> v[i];
	
	if(v[n - 1] != 2LL){
		cout << "-1\n";
		return 0;
	}
	
	ll curr = 2LL;
	ll minAns = 2LL, maxAns = 3LL;
	
	for(int i = n - 2 ; i >= 0 ; i --){
		ll lowm = (minAns + (v[i] - 1))/v[i];
		lowm *= v[i];
		
		ll him = maxAns/v[i];
		him *= v[i];
		
		minAns = lowm;
		maxAns = him + (v[i] - 1LL);
	}
	
	if(minAns > maxAns){
		cout << "-1\n";
		return 0;
	}
	
	cout << minAns << " " << maxAns << "\n";
	
	return 0;
}

Measured memory_bytes: 4008
var
	s:String[10];
	ans,now,i:Longint;
begin
	readln(s);
	ans:=1000;
	for i:=1 to length(s)-2 do begin
		now:=(ord(s[i])-48)*100+(ord(s[i+1])-48)*10+ord(s[i+2])-48;
		if now>753 then dec(now,753)else now:=753-now;
		if ans>now then ans:=now;
	end;
	writeln(ans);
end.


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000;
const int MOD = (int)1e9 + 7;
template <class T>
inline T in()
{
    T x;
    cin >> x;
    return x;
}

signed main()
{
    int n = in<int>();
    vector<int> v(n, 0);
    for (int i = 0; i < n; i++)
    {
        v[i] = in<int>();
    }
    int sum = 0;
    int cnt1 = 0;
    for (int i = 0; i < n; i++)
    {
        sum += v[i];
        if ((i & 1) == 0)
        {
            if (sum <= 0)
            {
                cnt1 += 1 - sum;
                sum = 1;
            }
        }
        else
        {
            if (sum >= 0)
            {
                cnt1 += sum + 1;
                sum = -1;
            }
        }
    }
    sum = 0;
    int cnt2 = 0;
    for (int i = 0; i < n; i++)
    {
        sum += v[i];
        if ((i & 1) == 0)
        {
            if (sum >= 0)
            {
                cnt2 += sum + 1;
                sum = -1;
            }
        }
        else
        {
            if (sum <= 0)
            {
                cnt2 += 1 - sum;
                sum = 1;
            }
        }
    }
    cout << min(cnt1, cnt2) << "\n";
}

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

int main()
{
    int L, R;
    int ans = 9999999;
    cin >> L >> R;

    if (R - L >= 2019)
    {
        cout << 0 << endl;
        return 0;
    }

    for (int i = L % 2019; i < (R % 2019); i++)
    {
        for (int j = i + 1; j <= (R % 2019); j++)
        {
            if (ans > (i * j) % 2019)
            {
                ans = (i * j) % 2019;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  long long N;
  cin >> N;
  long long ans = 0;
  for (long long i = 1; i <= N; i++) {
    if (i % 3 != 0 && i % 5 != 0)
      ans += i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
#include<assert.h>

#define M 1000007
#define NIL (-1)
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 0;
  else if ( ch == 'C') return 1;
  else if ( ch == 'G') return 2;
  else if ( ch == 'T') return 3;
  else assert(0);
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 4;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + key % (M-1); }

int find(char str[]){
  long long key = getKey(str);
  int p = h1(key);
  int d = h2(key);
  while(H[p][0] != '\0') {
    if(!strcmp(str,H[p])) return 1;
    p = p + d;
    if(p >= M) p %= M;
  }
  return 0;
}

int insert(char str[]){
  long long key = getKey(str);
  int p = h1(key);
  int d = h2(key);
  while(H[p][0] != '\0') p = (p + d) % M;
  strcpy(H[p], str);
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
  scanf("%d", &n);
    
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);

    if ( com[0] == 'i' ){
            insert(str);
    } else {
            if (find(str)){
        printf("yes\n");
            } else {
        printf("no\n");
            }
    }
  }

  return 0;
}

Measured memory_bytes: 13000
N = int(input())
X = []

for i in range(N):
  x = input()
  X.append(x)

def Judge():
  k = 0
  l = 0
  m = 0
  n = 0
  for i in range(N):
    if X[i] == 'AC':
      k+=1
    if X[i] == 'WA':
      l+=1
    if X[i] == 'TLE':
      m+=1
    if X[i] == 'RE':
      n+=1
  print("AC " + "x " + str(k))
  print("WA " + "x " + str(l))
  print("TLE " + "x " + str(m))
  print("RE " + "x " + str(n))
Judge()

Measured memory_bytes: 16152
#include<bits/stdc++.h>
using namespace std;
#define int long long
string s;
bool check;
int n,dem,ans;
signed main(){
	cin>>s;
	for(int i=0;i<s.size()-1;i++){
		if(s[i]=='A') dem++;
		else if(s[i]=='B'&&s[i+1]=='C'){
			ans+=dem;
			i++;
		}
		else dem=0;
	}
	cout<<ans;
}

Measured memory_bytes: 640
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>

using namespace std;

typedef long long ll;
ll n;

int main() {
	cin >> n;
	int x = n % 10;

	if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9) {
		cout << "hon" << endl;
	}
	else if (x == 0 || x == 1 || x == 6 || x == 8) {
		cout << "pon" << endl;
	}
	else if (x == 3) {
		cout << "bon" << endl;
	}

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int main() {
  int64_t n;
  cin >> n;
  vector <int64_t> v(5, 0);
  rep(i, n) {
    string s;
    cin >> s;
    if (s.at(0) == 'M') {
      v.at(0)++;
    } else if (s.at(0) == 'A') {
      v.at(1)++;
    } else if (s.at(0) == 'R') {
      v.at(2)++;
    } else if (s.at(0) == 'C') {
      v.at(3)++;
    } else if (s.at(0) == 'H') {
      v.at(4)++;
    }
  }
  int64_t ans = 0;
  vector <int64_t> p = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
  vector <int64_t> q = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
  vector <int64_t> r = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
  rep(i, 10) {
    ans += v.at(p.at(i))*v.at(q.at(i))*v.at(r.at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n,x,t;
  cin>>n>>x>>t;
  int k = (n+x-1)/x;
  cout<<k*t<<"\n";
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int a,b;
  cin >> a >> b;
  if(a > b) rep(i,a) cout << b;
  else rep(i,b) cout << a;
  cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int l[1000010];

int main(){
	int s;
	scanf("%d",&s);
	
	for(int i=1;;i++){
		if(l[s]==1){
			printf("%d\n",i);
			return 0;
		}
		l[s]=1;
		if(s%2==0)s/=2;
		else s=s*3+1;
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
  int a,b[10000],c,d,s,i;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&b[i]);
  }
  d=a-1;
  for(i=d;i>=0;i--){
    if (i>0)printf("%d ",b[i]);
    else printf("%d",b[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2036
#include <iostream>
#include <ctype.h>
#include <cstdio>
#include <string>
using namespace std;

int main() {
	string s;
	getline(cin, s);
	for(int i = 0; i < s.size(); i++) {
		if('a' <= s[i] && s[i] <= 'z') s[i] += 'A' - 'a'; 
	}
	cout << s << endl;;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    n -= x;
  }
  if (n < 0) {
    cout << -1 << '\n';
  } else {
    cout << n << '\n';
  }
  return 0;
}


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

using namespace std;

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


int main(){
 long n;
   cin >> n;

  long res=0;
  long num=0;
  
  rep(i,0,n){
   long a;
    cin >> a;
    
    if(a) {
      res+=(a+num)/2;
      num=(a+num)%2;
    }
    else {
      num=0;
    }
      
  }
  
   cout << res << endl;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,N;
map<int,int> m;
vector<int> v;

signed main() {
    cin >> n;
    N = pow(2,n);
    rep(i,N) {
        int s;
        cin >> s;
        m[s]++;
    }
    auto hoge = m.end();--hoge;
    v.pb(hoge->fi);
    hoge->se -= 1;
    if (hoge->se == 0) m.erase(hoge->fi);
    rep(k,n) {
        int vs = v.size();
        rep(i,vs) {
            auto hoge = m.lower_bound(v[i]);
            if (hoge == m.begin()) goto BREAK;
            --hoge;
            v.pb(hoge->fi);
            hoge->se -= 1;
            if (hoge->se == 0) m.erase(hoge);
            if (m.empty()) goto BREAK;
        }
    }
    BREAK:;
    if (v.size() == N && m.empty()) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

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

    if((s.front() == s.back()) ^ (s.size()%2)) {
        cout << "First" << endl;
    } else {
        cout << "Second" << endl;
    }

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstring>
using namespace std;
 
char tolower(char ch){
  if( 'A' <= ch && ch <= 'Z' ){
    return ch-'A'+'a';
  }else{
    return ch;
  }
}
 
int main(){
  int count=0;
  string W;
  cin>>W;
  string str;
  while(1){
    cin>>str;
    if(str=="END_OF_TEXT")break;
    for(int i=0;i<(int)str.size();i++){
      str[i]=tolower(str[i]);
    }
    if(str==W){
      count++;
    }
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 3172
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

vector<int> v;
int main(void) {
	int n;
	while(cin >> n) {
		while(n--) {
			int x;
			cin >> x;
			vector<int>::iterator it = upper_bound(v.begin(), v.end(), x, greater<int>());
			if(it == v.end())
				v.push_back(x);
			else
				*it = x;
		}
		cout << v.size() << endl;
	}
}


Measured memory_bytes: 892
#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 n;
  cin >> n;

  string s = to_string(n);
  int sum = 0;
  rep(i, s.size()){
    sum += s[i] - '0';
  }

  cout << (n%sum == 0 ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 2000
int toSum(char*);
int main(void)
{
  char str[LEN];
  int sum;
  for(;;)
    {
      scanf("%s",str);
      sum=toSum(str);
      if(sum==0) break;
      else printf("%d\n",sum);
    }
  return 0;
}
int toSum(char *str)
{
  int i;
  int len=strlen(str);
  int ret=0;
  for(i=0;i<len;i++) ret+=str[i]-'0';
  return ret;
}


Measured memory_bytes: 2052
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

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

ll lcm(ll a, ll b) {
    return min(LONGINF, (ll)(1.0 * a / gcd(a, b) * b));
}

// 中国剰余定理
// x = b_1 (mod_1), ..., x = b_k (mod_k), ... を満たす x を
// 0 <= x < lcm(mod_1, mod_2, ..., mod_k, ...) の範囲で求める

template <typename NumType, NumType LIMIT = NumType(1e10)>
struct CRT {
    pair<NumType, NumType> NIL;
    CRT() : NIL(-1, -1) {}
    
    NumType extgcd(NumType a, NumType b, NumType &p, NumType &q) {
        if(b == 0) {
            p = 1, q = 0;
            return a;
        }
        NumType d = extgcd(b, a%b, q, p);
        q -= a / b * p;
        return d;
    }

    pair<NumType, NumType> solve(NumType b1, NumType mod1, NumType b2, NumType mod2) {
        NumType p, q;
        NumType d = extgcd(mod1, mod2, p, q);
        
        if((b2 - b1) % d != 0) return NIL;
        NumType s = (b2 - b1) / d;
        NumType t = (s * p % (mod2 / d));

        // get lcm
        NumType lc = mod1 / d * mod2;
        NumType so = (b1 + mod1 * t) % lc;
        (so += lc) %= lc;
        return make_pair(so, lc);
    }

    // m, mod の vector をもらって、
    // CRT の解を (x, lcm(mod_1, mod_2, ..., mod_k, ...)) の形で返す
    pair<NumType, NumType> solve(vector<NumType> m, vector<NumType> mod) {
        assert(m.size() == mod.size());
        NumType so = 0, lc = 1;
        for(size_t i=0; i<m.size(); i++) {
            tie(so, lc) = solve(so, lc, m[i], mod[i]);
            if(so > LIMIT or so < 0) {
                return NIL;
            }
        }
        return make_pair(so, lc);
    }
};


int main() {
    ll N, M; cin >> N >> M;
    vector<__int128> m, mod;    
    vector<ll> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
        m.emplace_back(A[i] / 2);
        mod.emplace_back(A[i]);
    }

    CRT<__int128> crt;
    auto pr = crt.solve(m, mod);
    if(pr == crt.NIL) {
        cout << 0 << endl;
    }
    else {
        ll Z = pr.second, x = pr.first;
        ll ans = M / Z + (M % Z >= x);
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 7524
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (long long i = 0; i < (n); i++)
using namespace std;

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

    long long N;
    scanf("%lld",&N);

    long long L;
    scanf("%lld",&L);

    std::vector<std::string> S(N);
    REP(i, N)
        std::cin >> S[i];

    sort(S.begin(), S.end());

    REP(i, N)
        cout << S[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import defaultdict

n, p = na()
s = ns()

if 10 % p == 0:
    ans = 0
    for i in range(n - 1, -1, -1):
        if int(s[i]) % p == 0:
            ans += i + 1
    print(ans)
    exit(0)

c = [0] * (n + 1)
m = 1
for i in range(n - 1, -1, -1):
    t = int(s[i]) * m % p
    c[i] = (c[i + 1] + t) % p
    m *= 10
    m %= p

ans = 0
dic = defaultdict(int)
for i in range(n, -1, -1):
    ans += dic[c[i]]
    dic[c[i]] += 1

print(ans)

Measured memory_bytes: 43916
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define MOD 1000000007

ll kai[2000001], inv[2000001], sum[2000001];
int n, k;
ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n /= 2;
  }
  return res;
}
void init() {
  kai[0] = 1LL;
  for (ll i = 1LL; i <= n; i++) {
    kai[i] = kai[i - 1] * i;
    kai[i] %= MOD;
  }
  inv[n] = mod_pow(kai[n], MOD - 2LL, MOD);
  for (ll i = n - 1; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1);
    inv[i] %= MOD;
  }
}

ll comb(ll r, ll c) {
  ll res;
  res = kai[r];
  res *= inv[c];
  res %= MOD;
  res *= inv[r - c];
  res %= MOD;
  return res;
}

ll g(ll r, ll c) {
  ll res = 0LL;
  for (ll i = 0; i <= r; i++) {
    res += comb(i + c + 1, c);
    res %= MOD;
  }
  return res;
}
int main() {
  int r1, r2, c1, c2;
  ll ans = 0;
  scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
  n = 2LL * max(r2, c2) + 1LL;
  init();
  ans += g(r2, c2);
  ans -= g(r1 - 1, c2);
  if (ans < 0) {
    ans += MOD * (-ans / MOD + 1);
    ans %= MOD;
  }
  ans -= g(r2, c1 - 1);
  if (ans < 0) {
    ans += MOD * (-ans / MOD + 1);
    ans %= MOD;
  }
  ans += g(r1 - 1, c1 - 1);
  ans %= MOD;
  printf("%lld\n", ans);
}

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

int vis[25][25];

void inti(){
  for(int i=0;i<25;i++){
    for(int j=0;j<25;j++){
      vis[i][j]=0;
    }
  }
}

void dfs(int i,int j){
  if(vis[i][j]==0 || vis[i][j]==2)return;
  vis[i][j]=0;

    dfs(i-1,j);
    dfs(i,j-1);
    dfs(i,j+1);
    dfs(i+1,j);
}

int main(){
  int w,h;
  int i,j;
  char ch;
  int cnt;

  while(1){
    inti();
    cnt=0;
    cin >> w >> h;
    if(w==0 && h==0)break;

    for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
	cin >> ch;
	if(ch=='.'){
	  vis[i][j]=1;
	}else if(ch=='#'){
	  vis[i][j]=2;
	}else{
	  vis[i][j]=5;
	}
      }
    }
     for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
	if(vis[i][j]==5)dfs(i,j);
      }
     }
      for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
	if(vis[i][j]==0)cnt++;
      }
     }
      cout << cnt << endl;
  }
}
    

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

int main(){
  vector<int> A(5);
  for(int i = 0; i < 5; i++){
    cin >> A.at(i);
  }
  int ans = 0;
  for(int i = 0; i < 5; i++){
    if(A.at(i) == 0){
      ans = i + 1 ;
      break;
    }
  }
  
  cout << ans << endl;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1ll << 62)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};

struct edge{
  ll to,s,t;
  bool operator<(const edge &other)const{
    return t > other.t;
  }
};

int main(){
  
  const ll inf = (1ll << 61);
  int n,m,S;
  cin >> n >> m >> S;
  const int max_S = 5000;
  S = min(max_S,S);
  vector<vector<edge>> v(n);
  REP(i,m){
    int fr,to,a,b;cin >> fr >> to >> a >> b;
    fr--,to--;
    v[fr].push_back({to,a,b});
    v[to].push_back({fr,a,b});
  }
  vector<P> cost(n);
  REP(i,n)cin >> cost[i].first >> cost[i].second;
  priority_queue<edge> que;
  que.push({0,S,0});
  vector<vector<ll>> dist(n,vector<ll>(5001,inf));
  dist[0][S] = 0;
  auto push = [&](edge vv,edge vvv){
    if(vv.s < vvv.s)return ;
    int ns = min(vv.s-vvv.s,1ll*max_S);
    if(dist[vvv.to][ns] <= dist[vv.to][vv.s]+vvv.t)return ; 
    dist[vvv.to][ns] = dist[vv.to][vv.s]+vvv.t;
    que.push({vvv.to,ns,dist[vvv.to][ns]});
  };
  while(!que.empty()){
    edge e = que.top();que.pop();
    if(dist[e.to][e.s] != e.t)continue;
    push(e,{e.to,-cost[e.to].first,cost[e.to].second});
    for(auto nv : v[e.to])push(e,nv);
  }
  for(int i = 1;i < n;i++){
    ll res = inf;
    REP(j,5001)res = min(res,1ll*dist[i][j]);
    cout << res << endl;
  }



  

  return 0;
}

Measured memory_bytes: 11404
# -*- coding: utf-8 -*-

import sys
import itertools
from collections import defaultdict


def dijkstra(roads, st, ed, n):
    length = [float("inf") if i != st else 0 for i in range(n + 1)]
    q = set(range(n + 1))
    while len(q) != 0:
        a, ml = min([(i, x) for i, x in enumerate(length) if i in q], key=lambda x: x[1])
        q.remove(a)
        for b, l in roads[a].items():
            if length[b] > l + ml:
                length[b] = l + ml
    return length[ed]


def main():
    n, m, r = [int(i) for i in sys.stdin.readline().rstrip().split(" ")]
    target = set([int(i) for i in sys.stdin.readline().rstrip().split(" ")])
    roads = defaultdict(lambda: defaultdict(lambda: 100001))
    for line in sys.stdin:
        a, b, l = map(int, line.rstrip().split(" "))
        if roads[a][b] <= l:
            continue
        else:
            roads[a][b] = l
            roads[b][a] = l

    m_roads = defaultdict(lambda: defaultdict(lambda: 100001))
    for a, b in itertools.combinations(target, 2):
        l = dijkstra(roads, a, b, n)
        m_roads[a][b] = l
        m_roads[b][a] = l

    ans = float("inf")
    for seq in itertools.permutations(target):
        l = 0
        for i in range(len(seq) - 1):
            a = seq[i]
            b = seq[i + 1]
            l += m_roads[a][b]
        ans = min(ans, l)

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 6752
#include<stdio.h>
 int main(void){
    int n,x,i=0,j=0,k=0;
    while(1){
        int ans=0;
        scanf("%d %d",&n,&x);
        if(n==0&&x==0){
            break;
        }
        for(i=1;i<=n;i++){
            for(j=i+1;j<=n;j++){
                for(k=j+1;k<=n;k++){
                    if(i+j+k==x){
                        ans++;
                    }
                }
            }
        }
        printf("%d\n",ans);
    }


    return 0;
 }

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)
 
int main(){
    string s, t;
    cin >> s >> t;
    int N = (int)s.size();
    int n = (int)t.size();
 
    //ヒントの文字列Tを入れることができる部分の、最初のインデックスを格納する配列
    vector<int> able;
 
    //tが、答えとなる文字列Sの中に入る余地があるかどうかチェックする
    bool is = false;
    rep(i, N-n+1){
        //ヒント文字列Tとの比較用に部分文字列を抜き出す
        string part = s.substr(i, n);
        //ヒント文字列Tと、部分文字列で条件1を満たすかを判定するための変数
        bool match = true;
        rep(j, n){
            if(part[j] == '?') continue;
            else if(part[j] != t[j]) match = false;
        }
        if(match) able.push_back(i);
    }
    //条件1を満たすような部分が存在しないならば、答えを出力
    if(able.empty()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
 
    //条件1を満たすような部分が存在する時
    string S = "";;
    int len = (int)able.size();
    int key_index = able[len-1];
    rep(i, N){
        if(i == key_index){
            S += t;
            i += (n-1);
        }else if(s[i] == '?'){
            S.push_back('a');
        }else if(s[i] != '?'){
            S.push_back(s[i]);
        }
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 3552
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    ll n, *a, *b;
    cin >> n;
    a = new ll[n], b = new ll[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    sort(a, a+n);
    sort(b, b+n);

    if (n % 2) {
        cout << b[(n-1)/2] - a[(n-1)/2] + 1 << endl;
        return 0;
    }
    else {
        ll m_a = (a[n/2]+a[n/2-1]), m_b = (b[n/2]+b[n/2-1]);
        cout << m_b - m_a + 1 << endl;
        return 0;
    }
}

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

//素集合データ構造
// ref:https://ei1333.github.io/luzhiled/snippets/structure/union-find.html
struct union_find {
    // parent[v]==w(>=0):vの親はw
    // parent[v]==k(<0):vは根&&vの属するグループの要素数は-k
    vector<long long int> parent;
    //コンストラクタ
    union_find(long long int n) {
        parent.assign(n, -1);
    }
    // vの根を求める
    //求めると同時に親を根に置き換える(木の圧縮)
    long long int root(long long int v) {
        if (parent[v] < 0) {
            return v;
        } else {
            parent[v] = root(parent[v]);
            return parent[v];
        }
    }
    // vが属するグループの要素数を求める
    long long int size(long long int v) {
        return -parent[root(v)];
    }
    // vとwを繋げる
    void unite(long long int v, long long int w) {
        v = root(v);
        w = root(w);
        if (v == w) return;
        if (parent[v] < parent[w]) swap(v, w);
        parent[w] += parent[v];
        parent[v] = w;
    }
    // vとwが同値か判定
    bool isSame(long long int v, long long int w) {
        return root(v) == root(w);
    }
};

int main() {
    int n;
    cin >> n;
    vector<pair<int, pair<int, int>>> city(n);
    for (int i = 0; i < n; i++) {
        cin >> city[i].second.first >> city[i].second.second;
        city[i].first = i;
    }
    vector<pair<int, pair<int, int>>> edges;
    union_find uf(n);
    sort(city.begin(), city.end(),
         [](const pair<int, pair<int, int>> x,
            const pair<int, pair<int, int>> y) {
             return x.second.first < y.second.first;
         });
    for (int i = 0; i < n - 1; i++) {
        pair<int, pair<int, int>> c1 = city[i];
        pair<int, pair<int, int>> c2 = city[i + 1];
        edges.push_back(make_pair(c2.second.first - c1.second.first,
                                  make_pair(c1.first, c2.first)));
    }
    sort(city.begin(), city.end(),
         [](const pair<int, pair<int, int>> x,
            const pair<int, pair<int, int>> y) {
             return x.second.second < y.second.second;
         });
    for (int i = 0; i < n - 1; i++) {
        pair<int, pair<int, int>> c1 = city[i];
        pair<int, pair<int, int>> c2 = city[i + 1];
        edges.push_back(make_pair(c2.second.second - c1.second.second,
                                  make_pair(c1.first, c2.first)));
    }
    sort(edges.begin(), edges.end(),
         [](const pair<int, pair<int, int>> x,
            const pair<int, pair<int, int>> y) { return x.first < y.first; });
    int connected = 1;
    int ans = 0;
    auto itr = edges.begin();
    int stopper = 0;
    while (connected < n && itr != edges.end()) {
        if (!uf.isSame((*itr).second.first, (*itr).second.second)) {
            ans += (*itr).first;
            uf.unite((*itr).second.first, (*itr).second.second);
            connected++;
        }
        itr++;
        stopper++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6900
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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 double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int N;
    string S;
    cin >> N >> S;
    int A[N]{};
    rep(i,2){
        rep(j,2){
            rep(i,N) A[i] = 0;
            bool ok1{}, ok2{};
            A[0] = i;
            A[1] = j;
            for(int i=2;i<N;i++){
                if(A[i-1] == 0){
                    if(S[i-1] == 'o'){
                        A[i] = A[i-2];
                    }
                    else{
                        A[i] = (A[i-2] ^ 1);
                    }
                }
                else{
                    if(S[i-1] == 'o'){
                        A[i] = (A[i-2] ^ 1);
                    }
                    else{
                        A[i] = A[i-2];
                    }
                }
            }

            if(A[N-1] == 0){
                if(S[N-1] == 'o'){
                    if(A[N-2] == A[0]) ok1 = true;
                }
                else{
                    if(A[N-2] == (A[0] ^ 1)) ok1 = true;
                }
            }
            else{
                if(S[N-1] == 'o'){
                    if(A[N-2] == (A[0] ^ 1)) ok1 = true;
                }
                else{
                    if(A[N-2] == A[0]) ok1 = true;
                }
            }
            if(A[0] == 0){
                if(S[0] == 'o'){
                    if(A[N-1] == A[1]) ok2 = true;
                }
                else{
                    if(A[N-1] == (A[1] ^ 1)) ok2 = true;
                }
            }
            else{
                if(S[0] == 'o'){
                    if(A[N-1] == (A[1] ^ 1)) ok2 = true;
                }
                else{
                    if(A[N-1] == A[1]) ok2 = true;
                }
            }
            if(ok1 && ok2){
                rep(i,N){
                    if(A[i]){
                        cout << "W";
                    }
                    else{
                        cout << "S";
                    }
                }
                cout << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;

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

    int n;cin>>n;
    vector<int>d(n);
    rep(i,n)cin>>d[i];
    ll sum = 0;
    rep(i,n){
        for(int j = i + 1 ; j< n;j++)
        sum+=d[i]*d[j];
    }

    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 256
def main():
  x, y =  map(int,input().split())
  fm1 = y - 2 * x
  fm2 = 4 * x - y
  if y % 2 == 0 and fm1 >= 0 and fm2 >= 0:
    print("Yes")
  else:
    print("No")


if __name__ == '__main__':
  main()

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

int power(int a, int b) {
	int result = 1;
	while(b) {
		if(b % 2) result = (result * a) % P;
		a = (a * a) % P;
		b /= 2;
	}
	
	return result;
}

int C(int n, int k) {
    double res = 1;
    for (int i = 1; i <= k; ++i)
        res = res * (n - k + i) / i;
    return (int)(res + 0.01);
}

void solve() {
	string s;
	cin >> s;
	
	int n = s.length(), k;
	cin >> k;
	
	if(n < k) {
		cout << 0 << endl;
		return;
	}
	
	int ans = C(n, k) * power(9, k), digits = 0;
	for(int i = 0; i < n && k - digits; i++) {
		int d = s[i] - '0';
		ans -= (9 - d) * C(n - (i + 1), k - digits - 1) * power(9, k - digits - 1);
		if(d != 0) digits++;
	}	
	
	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <map>
using namespace std;
int main () {
long long n,m,a,b;long long sh=0;
cin>>n>>m;
map <long long,long long> mas;
for(int i=0;i<n;++i)
{
    cin>>a>>b;

    if (mas.count(a)==1) {mas[a]+=b;}
    else {mas[a]=b;}
}
map <long long, long long> :: iterator it = mas.begin();
    for (int i = 0; it != mas.end(); it++, i++) {
       if(m>it->second) {sh+=(it->first)*(it->second);m-=it->second;continue;}
       if(m<=it->second) {sh+=(it->first)*m;break; }
    }
    cout<<sh;
return 0;
}

Measured memory_bytes: 6528
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A_1116_B
{
    class Program
    {
        class A_2019_1116_B
        {
            public void run()
            {
                //入力部
                int N = int.Parse(Console.ReadLine());
                string str = Console.ReadLine();

                //処理
                bool isRep = false;
                if (N % 2 == 1) isRep = false;
                else
                {
                    isRep = true;
                    for(int i=0;i<N/2;i++)
                    {
                        if(str[i]!=str[i+N/2])
                        {
                            isRep = false;
                            break;
                        }
                    }
                }


                //出力
                if (isRep) Console.WriteLine("Yes");
                else Console.WriteLine("No");



            }
        }



        static void Main(string[] args)
        {
            A_2019_1116_B mainClass = new A_2019_1116_B();
            mainClass.run();


            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

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

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);

const int mn = 1000001;
vector<int> chp[mn];
vector<int> ch[mn];

bool isp[mn];
void init() {
	rep1(i, mn - 1) {
		for (int j = i; j < mn; j += i) {
			ch[j].push_back(i);
		}
	}
	fill(isp + 2, isp + mn, true);
	Rep(i, 2, mn) {
		if (!isp[i])continue;
		chp[i].push_back(i);
		for (int j = 2 * i; j < mn; j += i) {
			isp[j] = false;
			chp[j].push_back(i);
		}
	}
}
ll sum[mn];
ll sum2[mn];
ll score[mn];

ll mod_pow(ll x, ll n=mod-2) {
	ll res = 1;
	while (n > 0) {
		if (n % 2)res = res * x%mod;
		x = x * x%mod; n >>= 1;
	}
	return res;
}
ll inv[mn];

void solve() {
	rep1(i, mn - 1)inv[i] = mod_pow(i);
	int n; cin >> n;
	vector<ll> a(n);
	rep(i, n) {
		cin >> a[i];
		rep(j, ch[a[i]].size()) {
			int d = ch[a[i]][j];
			sum[d] += a[i];
			sum2[d] += a[i] * a[i];
			sum[d] %= mod; sum2[d] %= mod;
		}
	}
	rep(i, mn) {
		score[i] = sum[i] * sum[i] - sum2[i];
		score[i] = (score[i] % mod + mod) % mod;
		score[i] = score[i] * (mod + 1) / 2 % mod;
	}
	ll ans = 0;
	rep1(i, mn - 1) {
		if (score[i] == 0)continue;
		vector<int> &v = chp[i];
		int len = v.size();
		ll csum = 0;
		rep(j, 1 << len) {
			int cop = i;
			int id = 0;
			rep(k, len) {
				if (j&(1 << k)) {
					id ^= 1;
					cop /= v[k];
				}
			}
			if (id) {
				(csum -= score[i] * inv[cop]) %= mod;

			}
			else {
				(csum += score[i] * inv[cop]) %= mod;
			}
		}
		if (csum < 0)csum += mod;
		ans += csum; ans %= mod;
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	init();
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 198016
/*input
5
4 3 2 3 4

*/
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h> 

using namespace std;
long long mod=1e9+7;
 
typedef long long unsigned llu;
typedef long long int lld;
typedef long ld;
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scd(a) scanf("%d",&a)
#define scd2(a,b) scanf("%d%d",&a,&b)
#define scd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scf(a) scanf("%lf",&a)
#define scf2(a,b) scanf("%lf%lf",&a,&b)
#define scf3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define prfL(a) printf("%lf\n",a)
#define prfS(a) printf("%lf ",a)
#define Error(x) cerr << #x << " = " << (x) <<endl;
#define Error2(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define Error3(a,b,c) cerr<<"("<<#a<<" , "<<#b<<" , "<<#c<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<")\n";
#define Error4(a,b,c,d) cerr<<"("<<#a<<" , "<<#b<<" , "<<#c<<" , "<<#d<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<" , "<<(d)<<")\n";
#define errop(a) cerr<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
#define popcount __builtin_popcountll
// #define swap(a,b,t) t=a;a=b;b=t
typedef pair<lld,lld> PA;
 
#define lim 1000003
#define lim2 3003
// inline lld sqr(lld x) { return x * x; }
// map<lld,lld> M;
// deque<PA> Q;
// map<lld,lld>::iterator it;
// std::ios::sync_with_stdio(false);
 
// multiset<lld> S;
// set<lld> S;
// vector<PA> V[lim];
// priority_queue<PA> Q;
lld A[lim],B[lim];
// lld dp[103][103];
// char B[103][103];
// string S[lim],R[lim];
// PA P[lim];
// lld dp[1<<18];
// lld one,zero,ansR,numNodes;

lld powP(lld a,lld b){
    if(b==0) return 1%mod;
    lld k;
    k=powP(a,b/2);
    k=k*k%mod;
    if(b%2==0) return k;
    else return a*k%mod;
}


int main(){
    // std::ios::sync_with_stdio(false);
    lld T,i,j,h,l,r,k,s,b,c,a,d,q,p,n,m,w,x,y,v,z,t,curr,prev,sum,ans,pos,val,countA,secondMin,indicator;
    sc(n);
    rep(i,1,n) sc(A[i]);
    val=A[1];
    rep(i,2,n) val=max(val,A[i]);
    k=val;
    rep(i,0,k){
        t=max(i,k-i);
        bool flag=false;
        rep(i,1,n){
            if(B[i]==0 && A[i]==t){
                flag=true;
                B[i]=1;
                break;
            }
        }
        if(!flag){
            printf("Impossible\n");
            return 0;
        }
    }
    rep(i,1,k-1){
        t=max(i,k-i)+1;
        rep(i,1,n){
            if(A[i]==t){
                B[i]=1;
            }
        }
    }
    rep(i,1,n){
        if(B[i]==0){
            printf("Impossible\n");
            return 0;
        }
    }
    printf("Possible\n");
    return 0;
}


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

int main() {
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;
	if (a1 + a2 + a3 >= 22) {
		cout << "bust";
	}
	else {
		cout << "win";
	};
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		try {
			while (input.ready()) {
				String[] dataStr = input.readLine().split(" ");
				int[] dataInt = new int[dataStr.length];
				for (int i = 0; i < dataStr.length; i++) {
					dataInt[i] = Integer.valueOf(dataStr[i]);
				}
				System.out.println(getGCD(dataInt[0], dataInt[1]) + " " + getLCM(dataInt[0], dataInt[1]));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/***
	 * ?????§??¬?´???°
	 */
	public static int getGCD(int a, int b) {
		if (a == b)
			return a;
		int d = 1;
		if (a < b) {
			d = a;
		} else {
			d = b;
		}
		for (int i = d; i > 0; i--) {
			if ((a % i == 0) & (b % i == 0)) {
				return i;
			}
		}
		return 0;
	}

	/***
	 * ????°???¬?????°
	 *
	 * @param a
	 * @param b
	 * @return
	 */
	public static int getLCM(int a, int b) {
		int productA = a;
		int productB = b;
		while (productA <= 2000000000) {
			if (productA == productB) {
				return productA;
			}
			if (productA < productB) {
				productA += a;
			} else {
				productB += b;
			}
		}
		return 0;
	}
}

Measured memory_bytes: 24944
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;

int main(void) {
    int r, d, x;
    cin >> r >> d >> x;

    ll prev = r * x - d;
    for (int i = 1; i <= 10; ++i) {
        cout << prev << endl;
        prev = r * prev - d;
    }
}

Measured memory_bytes: 256