akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define ll long long
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

ll a[100010];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		int t;
		scanf("%d",&t);
		a[i+1]=(a[i]+t)%m;
	}
	n++;
	sortup(a,n);
	ll ans=0;
	for(int i=0;i<n;i++){
		ll t=1;
		while(i+t<n&&a[i+t]==a[i])t++;
		ans+=t*(t-1)/2;
		i=i+t-1;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 1660
package main

import "fmt"

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	var x, a, b int
	fmt.Scan(&x, &a, &b)
	if abs(x-a) > abs(x-b) {
		fmt.Println("B")
	} else {
		fmt.Println("A")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  long long int a,b,c,d,e,f;
  cin>>a;
  rep(i,100000){
    b=i*i;
    if(b>a)break;
    c=b;
  }  
  cout<<c;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 1000000007
//#define mod 1e18
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii map<int,int>
#define mll map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi  first

#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}

int main(){
	boost;
	
	int x,n;
	cin>>x>>n;
	int ans = x,m = inf;
	int arr[105];
	memset(arr,0,sizeof(arr));
	for(int i = 0;i<n;i++){
		int a;
		cin>>a;
		arr[a]++;
	}
	
	for(int i = 0;i<105;i++){
		if(arr[i]>0){
			continue;
		}
		
		if(m>abs(x-i)){
			m = abs(x-i);
			ans = i;
		}
	}
	
	cout<<ans;
	return 0;
}



Measured memory_bytes: 3688
var n,a,b,s,i,x,m:Longint;
begin
	read(n,a,b);
	for i:=1 to n do begin
		if i<10 then
			m:=i
		else if i<100 then
			m:=i div 10 + i mod 10
		else if i<1000 then
			m:= i div 100 + i div 10 mod 10 + i mod 10
		else if i<10000 then
			m:=i div 1000 + i div 100 mod 10 + i div 10 mod 10 + i mod 10
		else
			m:=1;
		if (a<=m)and(m<=b)then s:=s+i;
	end;
	writeln(s);
end.


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
using namespace std;
const int tINF = (int)INT_MAX;
const long long lINF = (long long)LLONG_MAX;
const long long mod = (ll)1e9 + 7;
ll binPow(ll a, ll n){
    if(n == 0) return 1;
    if(n & 1) return (a * binPow(a,n - 1))%mod;
    else{
        ll res = binPow(a, n >> 1);
        return (res * res) % mod;
    }
}
void calcFact(vector <ll> &fact){
    int n =(int)fact.size();
    fact[0] = 1;
    for(int i = 1; i < n; ++i){
        fact[i] = (i * fact[i - 1]) % mod;
    }
}
ll getFact(ll n){
    ll res = 1;
    for(int i = 1; i <= n; ++i){
        res *= (ll)i;
        res %= mod;
    }
    return res;
}
ll getInvFact(ll st, ll n){
    ll res = 1;
    for(int i = st; i <= n; ++i){
        res *= (ll)i;
        res %= mod;
    }
    return res;
}
ll mul(ll x, ll y){
    return (x * y) % mod;
}
ll del(ll x, ll y){
    return (x * binPow(y, mod - 2))%mod;
}
void calcC(int k, vector <ll> &nCk) {
    int n =(int)nCk.size();
    nCk[k] = 1;
    for(int i = k + 1; i < n; ++i){
        nCk[i] = del(mul(i,nCk[i - 1]), (i - k));
    }
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef DEBUG
			assert(freopen("inp", "r", stdin));
			assert(freopen("out", "w",stdout));
	#else
			#define cerr if(false)cerr
	#endif
    int n, k;
    cin >> n >> k;
    vector <ll> ar(n),fact(n + 1),br;
    vector<ll> nCk(n + 1);
    calcC(k -1,nCk);
    for(auto &i : ar)
        cin >> i;
    sort(all(ar));
    ll ans =0;
    for(int i = k - 1; i < n; ++i){
        ans += mul(ar[i], nCk[i]);
        ans += mod*(ll)1e5;
        ans %= mod;
    }

    ll ans2 = 0;
    reverse(all(ar));
    for(int i = k - 1; i < n; ++i){
        ans2 += mul(ar[i], nCk[i]);
        ans2 += mod*(ll)1e5;
        ans2 %= mod;
    }
//    cout << ans << " " << ans2 << '\n';
    cout << ((ans  - ans2)+mod)%mod<< '\n';
    cerr << "Time execute: " << (double)clock() / (double)CLOCKS_PER_SEC 
    << " sec" << endl;
}

Measured memory_bytes: 2560
# bellman_ford : O(V E)
# dijkstra : O(E log V), 負辺は無理
# warshall_floyd : O(V**3)
# deque

from collections import deque
import sys

input = sys.stdin.readline


def solve():
    inf = 10 ** 14 + 10

    n = int(input())
    e = tuple(set() for _ in range(n))
    for _ in range(n - 1):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        e[a].add((c, b))
        e[b].add((c, a))

    q, v = map(int, input().split())
    v -= 1

    d = [inf] * n
    d[v] = 0

    dq = deque()
    for cost, to in e[v]:
        dq.append((cost, to, v))
        # (cost, to, parent)

    while dq:
        c, v, p = dq.popleft()
        if d[v] != inf:
            continue
        d[v] = d[p] + c
        for cost, to in e[v]:
            if to == p:
                continue
            dq.append((cost, to, v))
            
    for _ in range(q):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        print(d[x] + d[y])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 59480
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using ld = long double; 
int INF = 1e9;

struct UnionFind{
  vector<int> d;
  UnionFind(int n):d(n,-1){}
  int find(int x){
    if(d[x]<0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x,int  y){
    x = find(x);y = find(y);
    if(x==y) return false;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x,int y) {return find(x) == find(y);}
  int size(int x) {return -d[find(x)];}
};

int main(){
  int n;cin >> n;
  vector<P> x(n),y(n);
  rep(i,n){
    int a,b;cin >> a >> b;
    x[i] = make_pair(a,i);
    y[i] = make_pair(b,i);
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  vector<tuple<int,int,int>> edge;
  rep(i,n-1){
    int co = x[i+1].first-x[i].first;
    edge.emplace_back(co,x[i+1].second,x[i].second);
    co = y[i+1].first - y[i].first;
    edge.emplace_back(co,y[i+1].second,y[i].second);
  }
  sort(edge.begin(),edge.end());
  // rep(i,4){
  //   int a,b,c;
  //   tie(a,b,c) = edge[i];
  //   printf("%d %d %d\n",a,b,c);
  // }
  ll ans = 0;
  UnionFind tree(100005);
  for(auto t:edge){
    int co,i,j;
    tie(co,i,j) = t;
    //printf("%d %d %d\n",co,i,j);
    if(tree.find(i) == tree.find(j)) continue;
    tree.unite(i,j);
    ans += co;
  }
  cout << ans << endl;
}


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

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long int ll;
typedef unsigned long long int ull;
#define inf INT_MAX
#define minf INT_MIN
#define watch(x)	cout<<(#x)<<"=>"<<x<<'\n';
#define sz(a) (int)(a).size()
#define all(x) x.begin(),x.end()


ll ans;
int arr[300009];
vi vr;
void solve()
{
    int n;  cin>>n;
    cout<<(!n)<<'\n';

    cout<<'\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int testc;  testc = 1;
    for(int t = 0; t < testc; ++t){
        solve();
    }
    return 0;
}

	//Sun 13 Sep 2020 05:33:06 PM IST


		/***astrainL3gi0N***/


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <atcoder/all>
#define F first
#define S second
using namespace std;
using namespace atcoder;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  int x[N],y[N];
  bool seen[N];
  int xnum[N];
  int ynum[N];
  dsu d(N);
  for (int i = 0; i < N; i++) {
    seen[i] = false;
  }
  set<int> Set;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
    x[i]--; y[i]--;
    xnum[x[i]] = i;
    ynum[y[i]] = i;
  } 
  int t = N-1;
  int minleft = 1000000;
  for (int i = 0; i < N; i++) {
    int ind = xnum[i];
    if (*(Set.lower_bound(ind)) == ind) {
      Set.erase(ind);
    }
    if (seen[ind]) {
      continue;
    }
    if (minleft > y[ind]) {
      minleft = y[ind];
      for (t; t > minleft; t--) {
        int now = ynum[t];
        if (x[now] > i) {
          Set.insert(now);
        }
      }
      for (auto itr = Set.begin(); itr != Set.end(); itr++) {
        d.merge(ind,*itr);
        seen[*itr] = true;
      }
    } else {
      continue;
    }
  }
  for (int i = 0; i < N; i++) {
    cout << d.size(i) << endl;
  }
  return 0;
}

Measured memory_bytes: 16576
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

def GCD(a, b):
    if(a < b):
        temp = a
        a = b
        b = temp
    a = a % b
    if(a == 0):
        return b
    else:
        return GCD(a, b)

n = int(input())

if(n <= 999):
    print('ABC')
else:
    print('ABD')

Measured memory_bytes: 12500
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;

int main(){
    int K;
    string S;
    cin >> K >> S;
    if(S.size()<=K){
        cout << S << endl;
    }else{
        for(int i=0;i<K;++i){
            cout << S.at(i);
        }
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3632
import math
SIN_T = math.sin(math.pi / 3)
COS_T = math.cos(math.pi / 3)


def koch(p0, p4):
    p1 = ((p0[0]*2 + p4[0])/3, (p0[1]*2 + p4[1])/3)
    p3 = ((p0[0] + p4[0]*2)/3, (p0[1] + p4[1]*2)/3)
    p2 = (COS_T*(p3[0]-p1[0]) + -SIN_T*(p3[1]-p1[1]) + p1[0],
          SIN_T*(p3[0]-p1[0]) + COS_T*(p3[1]-p1[1]) + p1[1])

    return [p1, p2, p3, p4]


if __name__ == "__main__":
    n = int(input())
    points = [(0, 0), (100, 0)]

    for _ in [0]*n:
        _points = [points[0]]
        for origin, dest in zip(points, points[1:]):
            _points += koch(origin, dest)

        points = _points

    for p in points:
        print(*p)


Measured memory_bytes: 6284
# 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); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
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)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n;
int k;
int a[101];
LL dp[101][101010];
LL rui[101010];
const LL mod = 1e9 + 7;
int main(){
    cin >> n >> k;
    REP(i, n)cin >> a[i];
    dp[0][0] = 1;
    REP(i, n){
        rui[0] = 0;
        REP(j, k + 1)rui[j + 1] = rui[j] + dp[i][j];
        for(int j = 0;j <= k;j++){
            dp[i + 1][j] = (rui[j + 1] - rui[max(0, j - a[i])] + mod) % mod;
        }
    }
    cout << dp[n][k] << endl;
}

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

int main(){
	int n,count=0;
	cin>>n;
	int p[n];
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	for(int i=1;i<n-1;i++){
		if((p[i]-p[i-1])*(p[i]-p[i+1])<0){
			count++;
		}else if(p[i]-p[i-1]==0 && p[i]-p[i+1]<0){
			count++;
		}else if(p[i]-p[i-1]<0 && p[i]-p[i+1]==0){
			count++;
		}
	}
	cout<<count;
	return 0;
}

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

int gcd(int a, int b) {
    while (a % b!= 0) {
        int tmp = b;
        b = a % b;
        a = tmp;
    }
    return b;
}

int main()
{
    int w, h, c, gd, area;
    scanf("%d %d %d", &w, &h, &c);
    if (h > w) swap(h, w);
    gd = gcd(w, h); gd *= gd;
    area = h * w;
    printf("%d\n", area/gd * c);

    return 0;
}



Measured memory_bytes: 2760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;

int main(){
  int h,w,n;
  cin >> h >> w >> n;
  
  int b=0,op=0;
  while(b < n){
    if(h >= w){
      b += h;
      w--;
    }else{
      b += w;
      h--;
    }
    op++;
  }
  
  cout << op << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

int main() {
    int h, w;
    cin >> h >> w;

    int r = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char a;
            cin >> a;
            r += a == '#';
        }
    }

    cout << (r == h + w - 1 ? "Possible" : "Impossible") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int F[45];

int fib(int n){
  if(n==0||n==1){
    return F[n]=1;
  }
  if(F[n]!=-1){
    return F[n];
  }
  return F[n]=fib(n-1)+fib(n-2);
}


int main(){
  int i,n;
  for(i=0;i<45;i++){
    F[i]=-1;
  }
  scanf("%d",&n);
  printf("%d\n",fib(n));
  return 0;
  
}



Measured memory_bytes: 2104
import sys
import fractions
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
st = [SL() for i in range(N)]
g = S()
#print(st)

f = 0
ans = 0
for s,t in st:
  if f == 0:
    if s == g:
      f = 1
  else:
    ans += int(t)
print(ans)

Measured memory_bytes: 63980
#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <algorithm>

int N, W;
std::vector<std::pair<int,int>> item{};
int dp[101][10001] = {};

int main(int argc, char **argv)
{
    std::cin >> N >> W;
    item.emplace_back(std::make_pair(0,0));
    for (int i=1; i<=N; ++i) {
        item.emplace_back(std::make_pair(0,0));
        std::cin >> item[i].first >> item[i].second;
    }

    for (int i=1; i<=N; ++i) {
        for (int w=1; w<=W; ++w) {
            if (w >= item[i].second) dp[i][w] = std::max(dp[i-1][w-item[i].second]+item[i].first, dp[i-1][w]);
            else dp[i][w] = dp[i-1][w];
        }
    }

    std::cout << dp[N][W] << std::endl;

    return 0;
}



Measured memory_bytes: 7004
#C
import math
mod = 10**9+7
N = int(input())

prime = [2]
for i in range(N):
    I = i+1
    In = math.ceil(math.sqrt(I))
    flag = 0
    for j in range(In):
        J = j+1
        if I%J == 0 and J!=1:
            flag = 1
            break
    if flag == 0 and I!=1:
        prime.append(I)
#print(prime)

ans = 1
for p in prime:
    q = 0
    pp = p
    while pp <= N:
        q+=(N//pp)
        pp*=p
    ans*=(q+1)
    
print(ans%mod)
    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N, M, ans;
    cin >> N >> M;
    vector<int> S(N), T(N);
    for(int i = 0; i < N; i++) {
        S[i] = 1;
        T[i] = 0;
    }
    T[0] = 1;
    for(int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        T[y] |= T[x];
        S[y]++, S[x]--;
        if(S[x] == 0) T[x] = 0;
    }
    ans = 0;
    for(int i = 0; i < N; i++) {
        ans += T[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

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

    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    int d = 0;

      for (int i=a; i<=b; i++){
        if (c % i == 0){
            d++;
        }
      }
        System.out.println(d);
  }
}



Measured memory_bytes: 26324
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>

using namespace std;
using ll = long long int;
using vec = vector<int>;

#define rep(n) for(int i = 0; i < (n); ++i)
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end(), greater<int>())
const int INF = 2147483647;
const ll  MOD = 1000000007;

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

    int ans = 0;
    int mn = x[0];
    rep(n) {
        if(x[i] <= mn) ans++;
        else continue;

        mn = x[i];
    }

    cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int n = s.size();
    VI s_cnt(256, 0), t_cnt(256, 0);
    REP(i, n) {
        s_cnt[s[i]]++;
        t_cnt[t[i]]++;
    }
    sort(ALL(s_cnt));
    sort(ALL(t_cnt));
    REP(i, 256) {
        if(s_cnt[i] != t_cnt[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 916
import java.io.BufferedReader;
import java.util.*;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.StringTokenizer;

 
public class Main {
	final static Long MOD = (int)1e9+7L; 
	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int n = fs.nextInt();
		Long [] pref = new Long[n];
		int [] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = fs.nextInt();
		}
		for(int i=n-1;i>=0;i--){
			if(i==n-1)
				pref[i]=0L;
			else {
				pref[i] = (pref[i+1]+a[i+1])%MOD;
			}
		}
		Long ans = 0L;
		for(int i=0;i<n;i++) {
			ans = (ans + (pref[i]*a[i])%MOD)%MOD;
		}
	  System.out.println(ans);
	}
	static final Random random=new Random();
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
 
	
}

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

int main(){
    int n, l, m;
    cin >> n >> l >> m;

    vector<vector<int>> a(n, vector<int>(l));
    vector<vector<int>> b(l, vector<int>(m));
    for(int i=0; i < n; i++)for(int j = 0; j < l; j++)cin >> a[i][j];
    for(int i=0; i < l; i++)for(int j = 0; j < m; j++)cin >> b[i][j];

    vector<vector<long long>>ans(n, vector<long long>(m));
    for(int i=0; i < n; i++){
        for(int j=0; j < m; j++){
            for(int k = 0; k < l; k++){
                ans[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    for(int i=0; i < n; i++){
        for(int j=0; j < m; j++){
            if(j == m-1)cout << ans[i][j] << endl;
            else cout << ans[i][j] << ' ';
        }
    }
    return 0;
}



Measured memory_bytes: 3204
N=int(input())

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
      
      
print(num2alpha(N).lower())

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,m;
  bool flag=true,ans=false;
  cin>>n>>m;
  vector<string> v(n),w(m);
  rep(i,n) cin>>v[i];
  rep(i,m) cin>>w[i];
  for(int i=0;i<n-m+1;i++){
    for(int j=0;j<n-m+1;j++){
      flag=true;
      for(int k=0;k<m;k++){
        for(int l=0;l<m;l++){
          if(v[i+k][j+l]!=w[k][l]){
            flag=false;
            break;
          }
          
          
          
        }
      }
      if(flag){
        ans=true;
        break;
      }
      
      
      
      
    }
  }
  
  
  if(ans){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  
}
///////////////////////////





Measured memory_bytes: 256
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}
///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}

func main() {
    let n = readInt()
    var flowerH = readInts()
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    
    var left = 0
    var right = 1
    var ans = 0
    while right <= flowerH.count && left < n{
        while right < n && flowerH[right - 1] <= flowerH[right] {
            right += 1
        }
        while left < n && flowerH[left] < 1 {
            left += 1
        }
        for i in left..<right {
            flowerH[i] -= 1
        }
        
        ans += left == right ? 0: 1
    }
    print(ans)
}
main()


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

int main() {
 string sen;
  cin >> sen;
  if (sen.at(sen.size()-1) == '2' || sen.at(sen.size()-1) == '4' || sen.at(sen.size()-1) == '5' ||
      sen.at(sen.size()-1) == '7' || sen.at(sen.size()-1) == '9' ) {
    cout << "hon" << endl;
  }
 else if (sen.at(sen.size()-1) == '0' || sen.at(sen.size()-1) == '1' || sen.at(sen.size()-1) == '6' ||
      sen.at(sen.size()-1) == '8' ) {
    cout << "pon" << endl;
  }
 else if (sen.at(sen.size()-1) == '3') {
    cout << "bon" <<endl;
  }
}

Measured memory_bytes: 3632
#include <string>
#include <iostream>
#include <set>
 
using namespace std;
 
// 文字列一つ受け取る場合
string s;
// 整数(max 2^31-1 or 10^9)一つ受け取る場合
// int x;
// int k;
// int n;
// set<int> a;

 
 
int main(){
    cin >> s;
   
    if(s.find('7')==string::npos){
        cout << "No";
    }else{
        cout << "Yes";
    }
}

Measured memory_bytes: 3104
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val n, m, q = sc.nextInt()

    val ar = bfs((1 to m).map(a => Vector(a)).toVector, m, n)

    val nums = Vector.fill(q) {
      val a, b, c = sc.nextInt()
      val d = sc.nextLong()
      (a, b, c, d)
    }

    val ans =
      ar.map(list => {
        nums.map {
          case (a, b, c, d) =>
            if (list(b - 1) - list(a - 1) == c) d else 0
        }.sum
      })

    println(ans.max)
  }

  @scala.annotation.tailrec
  def bfs(arr: Vector[Vector[Int]], m: Int, n: Int): Vector[Vector[Int]] = {
    if (arr.head.length == n) {
      arr
    } else {
      bfs(arr.flatMap(ar => {
        for (i <- ar.last to m) yield {
          ar :+ i
        }
      }), m, n)
    }
  }

  @scala.annotation.tailrec
  def gcd(a: Int, b: Int): Int = {
    if (b == 0) a else gcd(b, a % b)
  }
  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }
}


Measured memory_bytes: 81044
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int main(void) {
    Int r,x,d;

    cin>>r>>d>>x;

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

    return 0;
}




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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;


int main(){
  int N;
  cin >> N;
  vector<int> A(N), cnt(1e5, 0);
  REP(i, N){
    cin >> A[i];
    A[i]--;
    cnt[A[i]]++;
  }
  int ans = N;
  int even = 0;
  REP(i, 1e5){
    if(cnt[i] <= 1) continue;
    if(cnt[i] % 2 == 1){
      ans -= cnt[i]-1;
      cnt[i] = 1;
    }
    else{
      ans -= cnt[i]-1;
      even++;
    }
  }
  if(even % 2){
    ans--;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4016
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repl(i,n) for(int64_t i=0;i<(int64_t)(n);i++)
#define MAX_N 10000000 //10^7
#define ll int64_t
#define all(v) (v).begin(),(v).end()
using namespace std;

int main() {
    int n,maxx=0; cin>>n;
    string s; cin>>s;

    for(int i=1;i<n;i++) {
      int count=0;
      for(int j='a';j<='z';j++) {
        bool arul=0,arum=0;
        for(int l=0;l<i;l++) {
          if(s[l]==j) arul=1;
        }
        for(int m=i;m<n;m++) {
          if(s[m]==j) arum=1;
        }
        if(arul && arum) count++;
      }
      maxx=max(count,maxx);
    }
  cout<<maxx<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 1e18;
const int nax = 105;
int num[nax];
int dp[nax][4][2];
string s;
int n,k;
int calc(int pos,int non_zero,bool smaller)
 {
	if(non_zero>k)
	  return 0;
	if(pos == n && non_zero == k)
	  return 1;
	else if(pos >= n)
	  return 0;
	if(dp[pos][non_zero][smaller] == -1)
	 {
	   int now = 0;
	   if(smaller)
	     now += calc(pos+1,non_zero,1) + 9*calc(pos+1,non_zero+1,1);
	   else
	      {
			if(num[pos] == 0)
			  now += calc(pos+1,non_zero,0);
			else
			  now += calc(pos+1,non_zero,1) + (num[pos] - 1)*calc(pos+1,non_zero+1,1) + calc(pos+1,non_zero+1,0);
		  }
	   dp[pos][non_zero][smaller] = now;
	 }
   return dp[pos][non_zero][smaller];
 }
void solve()
 {
  cin>>s>>k;
  n = s.size();
  memset(dp,-1,sizeof dp);
  loop(i,0,n)
   num[i] = s[i] -'0';
  int ans = calc(0,0,0);
  cout<<ans;  
 }  
signed main()
 {   
  ios_base::sync_with_stdio(false);
  cin.tie(0); 
  cout.tie(0); 
   /*int t;
   cin>>t;
   loop(i,1,t+1)*/
      solve();
      
  //cerr<<END<<1.0*clock();
  return 0;
} 


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif
#define sz(a) ((int)(a).size())
#define found(m,x) ((m).find(x)!=(m).end())
#define uset unordered_set
#define umap unordered_map
#define a(x) (x).begin(),(x).end()
#define fo(i,n) for(int i=0;i<(int)n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<=(int)n:i>=(int)n;k<n?i++:i--)
#define input(v,n) fo(i,n)cin>>v[i]
using vi = vector<int>;
using vpi = vector<pair<int,int>>;
using pi = pair<int,int>;

const int nax = 1e5+7;
const int mod = 1e9+7; //1e9+2667 :: 0xcf : inf, 0xc0 -inf
const int inf = numeric_limits<int> :: max() - (int)9e6;
// ===================== MANASH =================== //

template<typename T>
struct prefix_sum {
    vector<T> pref;
    int n;
    template<typename U>
    prefix_sum(vector<U> &vec) {

        n = vec.size();
        pref.resize(n);
        pref[0] = vec[0];
        for( int i = 1; i < n; i++) {
            pref[i] = pref[i-1] + vec[i];
        }
    }
    T sum ( int i ) {
        return pref[i];
    }
    T sum ( int i, int j ) {
        if ( i == 0 ) return pref[j];
        else return pref[j] - pref[i-1];
    }
};

void test() {

	int n,m,k;
	cin >> n >> m >> k;
	vi C(n+1),D(m+1);
	for( int i = 0; i < n; i++) {
		cin >> C[i+1];
	}
	for( int i = 0; i < m; i++) {
		cin >> D[i+1];
	}
	prefix_sum<int> A(C),B(D);
	int i = n;
	int j = 0;
	int curr = A.sum(i);
	while( curr > k) {
		curr = A.sum(--i);
	}
	int ans = i;
	for( ; i >= 0; i--) {
		curr = A.sum(i);
		while( j <= m and curr + B.sum(j) <= k) {
			ans = max(ans,i+j);
			j++;
		}
	}
	cout << ans;

}

signed main() {

	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);

	#ifdef LOCAL
	freopen("input.txt","r",stdin);
	#endif

	int T = 1;
	// cin >> T;
	while(T--) {
		test();
		cout << "\n";
	}
	return 0;

}

Measured memory_bytes: 9496
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	ll n, m,ans=1; cin >> n >> m;
	while (2 * n <= m) {
		n *= 2;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int h, a;
    cin >> h >> a;
    int ans = (h + a - 1) / a;
    cout << ans << endl;
    return 0;
}


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

int gcd(int x, int y)
{
    if (y == 0) {
        return x;
    } else{
        return gcd(y, x % y);
    }
}

int main()
{
    long a, b, c, d;
    cin >> a >> b >> c >> d;
    long nc = b / c - (a - 1) / c;
    long nd = b / d - (a - 1) / d;
    long cd = c * d / gcd(c, d);
    long ncd = b / cd - (a - 1) / cd;
    long ans = b - a + 1 - (nc + nd - ncd);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;

int main(){
  string s, t;  cin >> s >> t;
  int ans = 0;
  REP(i, s.length()){
    if(s[i]==t[i])  ans++;
  }
  cout << ans << endl;
}


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

int main(){
    
    double a;
    double b;
    double C;
    
    double S;
    double L;
    double h;
    
    double PI = 3.1415926535;
    
    scanf("%lf %lf %lf", &a, &b, &C);
    
    S = (a*b*sin(C/180*PI))/2;
    
    double c = sqrt(a*a + b*b - 2*a*b*cos(C/180*PI));
    L = a + b + c;
    
    h = (2*S)/a;
    
    printf("%f\n%f\n%f\n", S, L, h);
    
    
    return 0;
}



Measured memory_bytes: 3444
def calc(N, H):
    if (N == 1):
        return 'Yes'
    for i in range(N - 1, 0, -1):
        if (H[i - 1] > H[i]):
            H[i - 1] -= 1
            if (H[i - 1] > H[i]):
                return 'No'
    return 'Yes'

N = int(input())
H = [int(s) for s in input().split(' ')]
print(calc(N, H))

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n][3];
    for(int i=0;i<n;i++)
    {
        for (int j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    int b[n][3];
    b[n-1][0]=a[n-1][0];
    b[n-1][1]=a[n-1][1];
    b[n-1][2]=a[n-1][2];
    for(int i=n-2;i>=0;i--)
    {
        for(int j=0;j<3;j++)
        {
            b[i][j]=a[i][j]+max(b[i+1][(j+1)%3],b[i+1][(j+2)%3]);
        }
    }
    int ans=0;
    
    for(int j=0;j<3;j++)
    {
        if(ans<b[0][j])ans=b[0][j];
    }
    cout<<ans;
}

Measured memory_bytes: 2560
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <type_traits>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define all(n) std::begin(n), std::end(n)
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;


void calc() {

	Int W, H, x, y; std::cin >> W >> H >> x >> y;
	std::cout << std::setprecision(10) << (double)W * (double)H / (double)2;
	std::cout << " ";
	if (2 * x == W && 2 * y == H)std::cout << 1;
	else std::cout << 0;
	
}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 256
A, B = map(int, input().split())

def reverseDigits(n):
    l = []
    r = 0
    j = 0
    while(n > 0):
        l.append(n % 10)
        n //= 10
    for i in l[::-1]:
        r += i * (10 ** j)
        j += 1
    return r

ans = 0
for i in range(A,B+1):
    r = reverseDigits(i)
    if i == r:
        ans += 1
print(ans)

Measured memory_bytes: 41068
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;

ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return (x + m2.x) % MOD;
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return (x - m2.x + MOD) % MOD;
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return (x * m2.x) % MOD;
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return mod(((*this).x * (*this).inv().x) % MOD);
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}

/* TEMPLATE ENDS HERE */

#define MAXN (1 << 20)

int n;
vector<int> a[MAXN];
int v[MAXN];
int col[MAXN];
int c[MAXN];
queue<int> q;

int main() {
	cout << fixed << setprecision(12);	
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int t1, t2;
		cin >> t1 >> t2;
		t1--;
		t2--;
		a[t1].push_back(t2);
		a[t2].push_back(t1);
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	sort(c, c + n, greater<int>());
	int cnt = 0;	
	q.push(0);
	v[0] = 1;
	while (!q.empty()) {
		int cur = q.front();
		q.pop();
		col[cur] = cnt++;
		for (auto& e: a[cur]) {
			if (!v[e]) {
				v[e] = 1;
				q.push(e);
			}
		}
	}
	int ret = 0;
	for (int i = 1; i < n; i++) {
		ret += c[i];
	}
	cout << ret << endl;
	for (int i = 0; i < n; i++) {
		cout << c[col[i]] << " ";
	}
	cout<< endl;
	return 0;
}


Measured memory_bytes: 28588
from fractions import*
n,*a=map(int,open(0).read().split())
*b,=a=a+[0]
r=range(n)
for i in r:a[i]=gcd(a[i],a[i-1]);b[-i-2]=gcd(b[-i-2],b[~i])
print(max(gcd(a[i-1],b[i+1])for i in r))

Measured memory_bytes: 16120
def insertionSort(A, N):
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
 
        print(' '.join(map(str, A)))
 
if __name__ == "__main__":
    n = int(input())
    a = [int(e) for e in input().split()]
    print(' '.join(map(str, a)))
    insertionSort(a, n)

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

int n;

int main() {
    cin >> n;

    for(int i = n; i < 1000; i++){
        if(n%10 == (n/10)%10 && (n/10)%10==(n/100)%10){
            cout << n;
            break;
        }
        n++;
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))
#define _max(x, y)(max(0, max((x), (y))))
#define _min(x, y)(max(0, min((x), (y))))

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

    cin.tie(0);
    ios::sync_with_stdio(false);

    long n;

    cin >> n;

    vector<long> v(n);
    map<long, char> table;
    long ans = 0;
    bool isNo = false;

    long i;

    for (i = 0; i < n; i++) cin >> v[i];

    i = 0;

    while (true) {
        ans++;

        if (table.find(i) != table.end()) {
            isNo = true;

            break;
        }

        table[i] = 1;
        i = v[i] - 1;

        if (i == 1) break;
    }

    if (isNo) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7296
program ABC049B
    implicit none
    integer(8)::H,W,i,j
    character(100)::so
    character(100),dimension(100)::S
    read(5,*)H,W,(S(i),i=1,H)

    do i=1,2*H
        do j=1,W
            so(j:j)=S((i+1)/2)(j:j)
        end do
        print'(A)',so(1:W)
    end do
end program ABC049B

Measured memory_bytes: 640
#include <iostream>
    #include <vector>
    #include <set>
    #include <algorithm>
     
    #define rep(i,n) for(int i=0;i< (n);++i)
    #define REP(i,n) for(int i=1;i<=(n);++i)
    #define ALL(a) (a).begin(),(a).end()
    using LLI = long long int;
    LLI GCD(LLI a,LLI b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
    LLI LCM(LLI a,LLI b){ return (a/GCD(a,b))*b; }
    using VI  = std::vector<LLI>;
    using PI  = std::pair<LLI,LLI>;
    using VVI = std::vector<VI>;
    using VPI = std::vector<PI>;
     
    int main() {
        std::ios::sync_with_stdio(false);
     
        LLI count[1000] = {};
        LLI H,W;
        std::cin >> H >> W;
        std::string S;
        rep(i,H){
            std::cin >> S;
            rep(j,W)
            ++count[S[j]];
        }
        LLI mod_count[4] = {};
        for(int c='a';c<='z';++c) {
            ++mod_count[count[c]%4];
        }
     
        bool flag = false;
        if(H%2==0&&W%2==0){
            flag = mod_count[1] == 0 && mod_count[2] == 0 && mod_count[3] == 0 ;
        } else if(H%2==1&&W%2==1) {
            flag = mod_count[2]+mod_count[3] <= (H/2+W/2) && mod_count[1]+mod_count[3] == 1;
        } else {
            if(H%2==0) std::swap(H,W);
            // H -> odd, W -> even
            flag = mod_count[1] == 0 && mod_count[2] <= W/2 && mod_count[3] == 0 ;
        }
     
        std::cout << (flag?"Yes":"No") << std::endl;
        return 0;
    }

Measured memory_bytes: 256
use std::io::*;


fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let nums: Vec<i32> = buf.split_whitespace().map(|n| n.parse().unwrap()).collect::<Vec<i32>>();
    
    for i in 0..5 {
        if nums[i] == 0 {
            let out = stdout();
            let mut out = out.lock();
            writeln!(out, "{}\n", i + 1).unwrap();
            return;
        }
    }
}


Measured memory_bytes: 2108
#include<iostream>
using namespace std;
int main(){
  int a, b; 
  cin >> a >> b;
  if (b==1){
    cout << 0 << endl;
    return 0;
  }
  int sum = a, cnt = 1;
  while(sum < b){
    sum += a-1;
  	cnt += 1;
  }
  cout << cnt << endl;
  return 0;
}
  

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    int ans = 0, l, r;
    for(int in=0;in<n;in++) {
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
	int x,root,check;
	scanf("%d",&x);
	root=ceil(sqrt(x));
	check=root;
	while((check!=1)&&(x!=2)){
		while(check>=2){
			if((x%check)==0){
				check=root;
				x++;
			}else{
				check--;
			}
		}
	}
	printf("%d",x);
	return 0;
}

Measured memory_bytes: 128