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

using namespace std;

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

typedef long long ll;

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

 
  
  int h,w;
  cin >> h >> w;
  
  const int inf=100000;
  
  vector<string> s(h);
  int white=0;
  rep(i,0,h) {
    cin >> s[i];
   rep(j,0,w) if(s[i][j]=='.') white++;
  }
vector<vector<int>> dist(h,vector<int>(w,inf));
queue<pair<int,int>> que;

vector<pair<int,int>> dx(4,make_pair(0,0));
 dx[0].first=1;
 dx[1].first=-1;
 dx[2].second=1;
 dx[3].second=-1;
  
  
dist[0][0]=1;
que.push(make_pair(0,0));
while(!que.empty()){
 int x,y;
  tie(x,y)=que.front();
  que.pop();
  for(auto v:dx){
  if(-1<x+v.first&&x+v.first<h&&-1<y+v.second&&y+v.second<w&&dist[x+v.first][y+v.second]==inf&&s[x+v.first][y+v.second]=='.'){
  dist[x+v.first][y+v.second]=dist[x][y]+1;
  que.push(make_pair(x+v.first,y+v.second));
  }
  }
}
 if(dist[h-1][w-1]==inf) cout << -1 << endl;
 else cout << white-dist[h-1][w-1] << endl;
 
}





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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e7+23;

long long f[N];

void solve() {
  for (int i = 1; i < N; ++i) {
    for (int j = i; j < N; j+=i) {
      ++f[j];
    }
  }
  int n; scanf("%d", &n);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += i*f[i];
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 81916
n = gets.to_i
data = []
n.times {
  a = gets.to_i
  tmp = []
  a.times do
    x, y = gets.strip.split.map(&:to_i)
    tmp << [x - 1, y]
  end
  data << tmp
}

ans = 0
[0, 1].repeated_permutation(n) do |bits|
  flg = true
  bits.each_with_index do |bit, i|
    next if bit == 0
    data[i].each do |x, y|
      unless bits[x] == y
        flg = false
      end
    end
  end
  if flg
    ans = [ans, bits.inject(&:+)].max
  end
end

puts ans


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
	int a,b;
	cin >> a >> b;
	cout << max({2 * a - 1, 2 * b - 1, a + b}) << endl;
	return 0;
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int x;
    cin >> x;

    vector<pair<long long, long long>> powers;
    for (long long i=-120; i<=120; i++)
        powers.emplace_back(i, i * i * i * i * i);

    for (auto &p : powers)
        for (auto &q : powers)
            if (p.second - q.second == x) {
                cout << p.first << " " << q.first << "\n";
                return 0;
            }

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x)
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define inf std::numeric_limits<int>::max();
#define highest_2_pow(n)  __builtin_clzll((long long)0)- __builtin_clzll((long long)n) - 1
//-----------------------------------------------------------------------------------------------------
#define lli long long int 
#define int long long
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define vi vector<int>
#define vlli vector<long long int>
#define si set<int>
#define slli set<long long int>
#define mt make_tuple
#define mp make_pair
#define eb emplace_back
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
//---------------------------------------------------
using namespace std;
// GCD and LCM are available
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}

void faster(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}
pair<int,int> max_sum(vector<int> &A, int As, vector<pii> &q, int qs){
    // cout<<As<<" "<<qs<<endl;
    if(As==A.size() || qs<0) return {0,As};
    int sum=0;
    int C,B;
    C = q[qs].first;
    B = q[qs].second;
    auto itr = upper_bound(A.begin()+As,A.end(),C);
    // cout<<"-- "<<*itr<<endl;
    int noe = min(B,(itr-A.begin()-As));
    // error(noe);
    sum+=noe*C;
    As+=noe;
    qs--;
    int nextSum,nextAs;
    tie(nextSum, nextAs) = max_sum(A,As,q,qs);
    return {sum+nextSum,nextAs};
}
void solve(){
    int n,m;
    cin>>n>>m;
    vector<int> A(n);
    rep(i,0,n) cin>>A[i];
    sort(all(A));
    vector< pii > q(m);
    rep(i,0,m) cin>>q[i].second>>q[i].first;
    sort(all(q));
    int sum,lastAi;
    tie(sum,lastAi) = max_sum(A,0,q,m-1);
    rep(i,lastAi,n) sum+=A[i];
    cout<<sum<<endl;


}
signed main()
{
    faster();
    int t=1;
    //cin>>t;
    while(t--) solve();
}

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


struct Node {
    int key;
    Node *right,*left,*parent;
    };

Node *root,*NIL;

void insert(int k){
    Node *y=NIL;
    Node *x=root;
    Node *z;

    z=(Node *)malloc(sizeof(Node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;

    while(x!=NIL){
        y=x; 
        if(z->key < x->key){
            x=x->left;
        }else{
            x=x->right;
        }
    }
    z->parent=y;
    if(y==NIL){
        root=z;
    }else{
        if(z->key < y->key){
            y->left=z;
        }else{
            y->right=z;
        }
    }
}


void preorder(Node* u){
    if(u==NIL)return;
    cout<<" "<<u->key;
    preorder(u->left);
    preorder(u->right);
}
void inorder(Node *u){
    if(u==NIL)return;
    inorder(u->left);
    cout<<" "<<u->key;
    inorder(u->right);
}

int main(){
    int m;
    cin>>m;
    string s;
    int k;
    rep(i,m){
        cin>>s;
        if(s=="insert"){
            cin>>k;
            insert(k);
        }
        else if(s=="print"){
            inorder(root);
            cout<<endl;
            preorder(root);
            cout<<endl;
        }
    }
        return 0;
}

    


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

int main(){
    string S;
    cin >> S;

    int n=S.length();
    ll Snum=stoll(S);
    int ans=999;
    for(int i=0;i<n-2;i++){
        int M=abs(Snum%1000-753);
        ans=min(M,ans);
        if(ans==0) break;
        Snum=Snum/10;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
long long gcd(long long a, long long b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long T[100];
int main(){
  int N;
  scanf("%d", &N);
  for(int i=0;i<N;++i) {
    scanf("%lld", &T[i]);
  }
  long long ans=T[0];
  for(int i=1;i<N;++i) {
    long long g=gcd(ans, T[i]);
    ans = ans * (T[i] / g);
  }
  printf("%lld\n", ans);
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=505;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
//inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int h,w,r[MAXN][MAXN],b[MAXN][MAXN];char s[MAXN];
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	h=read(),w=read();
	Rep(i,1,h){
		scanf("%s",s+1);
		Rep(j,1,w)if(s[j]=='#')r[i][j]=b[i][j]=1;
	}Rep(i,1,h)r[i][1]=b[i][w]=1;
	Rep(i,1,h)Rep(j,2,w-1)if(i&1)r[i][j]=1;else b[i][j]=1;
	Rep(i,1,h){Rep(j,1,w)putchar(r[i][j]?'#':'.');puts("");}puts("");
	Rep(i,1,h){Rep(j,1,w)putchar(b[i][j]?'#':'.');puts("");}
	return 0;
}




Measured memory_bytes: 5708
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int h,w,k;
  cin >> h >> w >> k;
  vector<vector<long>> dp(h+1,vector<long>(w,0));
  dp.at(0).at(0) = 1;
  long data[8] = {1,1,2,3,5,8,13,21};
  for(int i=1;i<=h;i++){
    rep(j,w){
      long l,r;
      if(j == 0) l = 0;
      else{
        l = dp.at(i-1).at(j-1) * data[j-1] * data[w-1-j];
      }
      if(j == w-1) r = 0;
      else{
        r = dp.at(i-1).at(j+1) * data[j] * data[w-2-j];
      }
      long m = dp.at(i-1).at(j) * data[j] * data[w-1-j];

      dp.at(i).at(j) = (l + r + m)%MOD;
    }
  }
  cout << dp.at(h).at(k-1) % MOD << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		System.out.println(solve());
	}

	public static String solve() {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int A = sc.nextInt();
		int sum = 0;
		for (int i = 0; i < A; i++) {
			sum += sc.nextInt();
		}
		
		return sum >= H ? "Yes" : "No";
	}
}


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


class Program
{


    static void Main(string[] args)
    {
        Solve();
    }

    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        var k = sc.intarr;
        int a = k[0];
         k = sc.intarr;
        int b = k[0];
        k = sc.intarr;
        int c = k[0];
        k = sc.intarr;
        int d = k[0];


        wr.wri(Math.Min(a, b) + Math.Min(c, d));



    }


}
    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => strarr.Select(char.Parse).ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int r, c, k;
    cin >> r >> c >> k;
    vector<vi> vmp(r, vi(c));
    rep(i, k) {
        int ri, ci, v;
        cin >> ri >> ci >> v;
        --ri; --ci;
        vmp[ri][ci] = v;
    }
    vector<vector<vll>> dp(r+1, vector<vll>(c+1, vll(4)));
    rep(i, c+1) rep(j, 4) dp[0][i][j] = 0;
    rep(i, r+1) rep(j, 4) dp[i][0][j] = 0;
    rep(i, r+1) rep(j, c+1) dp[i][j][0] = 0;
    vector<vll> vals(r+1, vll(c+1));
    rep1(i, r) rep1(j, c) {
        rep1(t, 3) {
            if (vmp[i-1][j-1] == 0) dp[i][j][t] = max(vals[i-1][j], dp[i][j-1][t]);
            else {
                ll val1 = max(vals[i-1][j]+vmp[i-1][j-1], dp[i][j-1][t-1]+vmp[i-1][j-1]);
                ll val2 = max(vals[i-1][j], dp[i][j-1][t]);
                dp[i][j][t] = max(val1, val2);
            }
        }
        rep(t, 4) vals[i][j] = max(vals[i][j], dp[i][j][t]);
    }
    ll ans = 0;
    rep(i, 4) ans = max(ans, dp[r][c][i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 742300
#include <bits/stdc++.h>
#define ll long long int
#define pr pair<ll, ll>
#define tp tuple<ll, ll, ll>
using namespace std;
long long int mod = 1e9 + 7;

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

    ll n, k;
    cin >> n >> k;
    ll a[n + 1];
    for (ll i = 0; i < n + 1; i++)
    {
        a[i] = i;
    }
    ll sum[n + 1], bac[n + 1];
    sum[0] = 0;
    for (ll i = 1; i < n + 1; i++)
        sum[i] = a[i] + sum[i - 1];
    bac[n] = a[n];
    for (ll i = n - 1; i >= 0; i--)
        bac[i] = bac[i + 1] + a[i];
    ll ans = 0;
    for (ll i = k; i <= n + 1; i++)
    {
        ans += (bac[n + 1 - i] - sum[i - 1] + 1 + mod) % mod;
    }

    cout << ans % mod << endl;

    return 0;
}

Measured memory_bytes: 8228
#include <iostream>
using namespace std;
int main() {
	int h;
	int w;
	int n;
	int a;
	int i = 0;

	cin >> h;
	cin >> w;
	cin >> n;
	if (h > w)
	{	
		a = h;
	}
	else
	{
		a = w;
	}

	if (a > n + 1)
	{
		cout << i + 1;
	}
	else if (h > w) {
		while (h < n + 1) {	
			if (h == n)break;
			h = h + a;
			i++;
		}
		cout << i + 1;
	}
	else {

		while (w < n + 1) {	
			if (w == n)break;
			w = w + a;

			i++;
		}
		cout << i + 1;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

ll dp[110][200100];

int main() {
    int N, W; cin >> N >> W;
    rep(i, 110) rep(j, 200100) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i, N) {
        int w, v; cin >> w >> v;
        rep(j, 100100) {
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][j+v], dp[i][j] + w);
        }
    }
    ll ans = 0;
    rep(i, 200100) if(dp[N][i] <= W) chmax(ans, i);
    cout << ans << endl;
}

Measured memory_bytes: 175596
q=int(input())
for i in range(q):
    a,b=map(int,input().split())
    left=0
    right=a*b
    for i in range(100):
        mid=(left+right)//2
        if mid*mid<a*b:
            left=mid
        else:
            right=mid
    ret=left*2
    if ret==0:
        print(ret)
        continue
    if (a*b-1)//left==left:
        ret-=1
    if min(a,b)<=left:
        ret-=1
    print(ret)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//    std::sort(a.begin(), a.end(), std::greater<int>() );
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int n;
    int ans=0;
    cin>>n;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        ans+=(b-a+1);
    }
    cout<<ans<<endl;
    return 0;

}

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

// AtCorder用のTemplate
namespace Atcoder{
    public class main{

        // 標準入力用汎用関数
        static string readString(){return Console.ReadLine();}
        static int readInteger(){return int.Parse(Console.ReadLine());}
        static long readLong(){return long.Parse(Console.ReadLine());}
        static double readDouble(){return double.Parse(Console.ReadLine());}
        static decimal readDecimal(){return decimal.Parse(Console.ReadLine());}

        static List<char> readCharL(char separator=' '){return Console.ReadLine().Split(separator).Select((x) => Convert.ToChar(x)).ToList();}
        static List<string> readStringL(char separator=' '){return Console.ReadLine().Split(separator).ToList();}
        static List<int> readIntegerL(char separator=' '){return Console.ReadLine().Split(separator).Select((x) => int.Parse(x)).ToList();}

        static void print<T>(T args){Console.WriteLine(args);}
        static void printL<T>(List<T> _list){Console.WriteLine(string.Join(",", _list));}

        public static void Main(string[] args)
        {
            var a = readIntegerL();
            var b = readIntegerL();
            print((a[0] -  b[0]) * (a[1] -  b[1]));
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main() {

	int X;
	cin >> X;

	for (int i = -120; i <= 120; ++i)
	{
		for (int j = -120; j <= 120; ++j)
		{
			if (powl(i, 5) - powl(j, 5) == X) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3628
import java.util.*;
class Main{
    public static void main(String[]args){
        Scanner scanner = new Scanner(System.in);
        String[] S = scanner.nextLine().split("");
        String[] T = scanner.nextLine().split("");
        int cnt = 0;

        for(int i=0;i<S.length;i++){
            if(!(S[i].equals(T[i]))){
                cnt += 1;
            }
        }

        System.out.println(cnt);
        scanner.close();
    }
}

Measured memory_bytes: 66508
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    vll dp(n+1);
    rep(i, n+1) dp[i] = INF;
    rep(i, n) *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
    ll ans = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
    cout << ans << endl;
}



Measured memory_bytes: 4428
use std::io::Read;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let n: usize = s.trim().parse().unwrap();
    let mut mp = std::collections::HashMap::<(usize, usize), u64>::new();
    let mut ans = 0u64;
    for i in 1..n + 1 {
        let k2 = i % 10;
        let mut k1 = i;
        while k1 >= 10 {
            k1 /= 10;
        }
        let cnt = mp.entry((k1, k2)).or_insert(0);
        *cnt += 1;
    }
    for i in 1..10 {
        for j in 1..10 {
            match (mp.get(&(i, j)), mp.get(&(j, i))) {
                (Some(val1), Some(val2)) => ans += val1 * val2,
                _ => (),
            }
        }
    }
    println!("{}", ans);
}


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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    // unsigned long a,b;
    string a, b;
    cin >> a >> b;
    if(a.size() > b.size()) {
        cout << "GREATER" << endl;
        return 0;
    } else if(a.size() < b.size()) {
        cout << "LESS" << endl;
        return 0;
    } else {
        rep(i, a.size()) {
            if(a[i] > b[i]) {
                cout << "GREATER" << endl;
                return 0;
            } else if(a[i] < b[i]) {
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int S,W;
    cin >> S >> W;
    cout << (S<=W? "unsafe\n":"safe\n");
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
    int h, w, m; cin >> h >> w >> m;
    vector<int> hor(h, 0), ver(w, 0);
    vector<P> bomb(m);
    rep(i, m) {
        cin >> bomb[i].first >> bomb[i].second; bomb[i].first--; bomb[i].second--;
        hor[bomb[i].first]++;
        ver[bomb[i].second]++;
    }
    vector<int> hor2 = hor; vector<int> ver2 = ver;
    sort(rALL(hor));
    sort(rALL(ver));
    ll ans = hor[0] + ver[0];
    int horNum, verNum;
    horNum = verNum = 0;
    rep(i, h) {
        if (hor[i] == hor[0]) horNum++;
        else break;
    }
    rep(i, w) {
        if (ver[i] == ver[0]) verNum++;
        else break;
    }
    int num = 0;
    rep(i, m) {
        if (hor2[bomb[i].first] == hor[0] && ver2[bomb[i].second] == ver[0]) num++;
    }
    if (num == horNum * verNum) ans--;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10364
package main

import (
  "fmt"
  "math"
)

func abs(a int) int {
  return int(math.Abs(float64(a)))
}

func main() {
  var N int
  fmt.Scan(&N)
  
  h := make([]int, N)
  for i := 0; i < N; i++ {
    fmt.Scan(&h[i])
  }
  
  dp := make([]int, N)
  for i := 1; i < N; i++ {
    dp[i] = abs(h[i-1] - h[i]) + dp[i-1]
    if i > 1 {
      if p := abs(h[i-2] - h[i]) + dp[i-2]; dp[i] > p {
        dp[i] = p
      }
    }
  }
  fmt.Println(dp[N-1])
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define ll   long long int
#define watch(x) cerr<<(#x)<<" is "<<x<<nl;
#define fi(a,b) for(ll i=a;i<b;i++)
#define fj(a,b) for(ll j=a;j<b;j++)
#define mp make_pair
#define ff first 
#define ss second
#define all(v) (v).begin(),(v).end()
#define pb(i) push_back(i)
#define mem(v,a) memset((v),a,sizeof(v));
#define mll map<ll,ll>
#define vll vector<ll>
#define nl endl
const long long inf=1e18+1e17;
const  int mod=998244353;
const ll  N=600032LL;
ll fac[N+2]; ll inv[N+2];

ll add(ll a,ll b){a+=b;if(a>=mod)a-=mod;if(a<0)a+=mod;return a;} 

ll mul(ll a,ll b){return ((a)*1LL*(b))%mod;}

ll power(ll a,ll n){ll res=1;while(n){if(n&1){
res=mul(res,a);} n>>=1,a=mul(a,a);}return res;}

ll fact(ll n){
	if(n==0||n==1)
		return 1;
	return n*fact(n-1);
}

void solve(){
	ll n,k;cin>>n>>k;
	vll v(n);
	fi(0,n)cin>>v[i];
	ll ar[n];memset(ar,0,sizeof(ar));
	ll i=0;
	for(;ar[i]==0&&k>0;i=v[i]-1){	k--;ar[i]++;}
	if(k<=0){cout<<i+1;return;}
	ll len=1;
	for(ll j=v[i]-1;j!=i;j=v[j]-1){	len++;}
	k=k%len;
	
	while(k-->0)	i=v[i]-1;
	cout<<i+1;
}
int main(){
	ll t;t=1;
	while(t--){
		solve();
	}
	return 0;
}



Measured memory_bytes: 6428
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    string c[3];
    rep(i, 3) cin >> c[i];

    cout << c[0][0] << c[1][1] << c[2][2] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vi d(N);
    cin >> d;
    REP(i, N)
    FOR(j, i + 1, N) {
        ans += d[i] * d[j];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3576
import java.util.Scanner;


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

    static int[][] d;

    public static void main(String[] args) {
        while (true) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int s = sc.nextInt();
            int g1 = sc.nextInt();
            int g2 = sc.nextInt();
            if (n == 0) break;

            d = new int[n + 1][n + 1];

            init(n);
            scanRoad(m);
            warshallFloyd(n);
            calcCost(n, s, g1, g2);

        }


    }

    static void warshallFloyd(int n) { // nは頂点数
        for (int i = 1; i <= n; i++)      // 経由する頂点
            for (int j = 1; j <= n; j++)    // 開始頂点
                for (int k = 1; k <= n; k++)  // 終端
                    d[j][k] = Math.min(d[j][k], d[j][i] + d[i][k]);
    }

    static void scanRoad(int m) {
        for (int i = 0; i < m; i++) {
            int b1 = sc.nextInt();
            int b2 = sc.nextInt();
            int c = sc.nextInt();

            d[b1][b2] = c;
        }
    }

    static void calcCost(int n, int s, int g1, int g2) {
        int min = Integer.MAX_VALUE/10;
        for (int i = 1; i <= n; i++) {
            min = Math.min(min, d[s][i] + d[i][g1] + d[i][g2]);
        }
        System.out.println(min);
    }

    static void init(int n) {
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                d[i][j] = Integer.MAX_VALUE / 10;
                if(i==j) d[i][j]=0;
            }
        }
    }
}

Measured memory_bytes: 63108
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
using ll = long long;

int n, m;
ll xyz[1000][3];

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

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> xyz[i][j];
        }
    }

    ll ans = 0;
    for (int bit = 0; bit < 8; ++bit) {
        priority_queue<ll> pq;
        for (int i = 0; i < n; ++i) {
            ll tmp = 0;
            for (int j = 0; j < 3; ++j) {
                tmp += xyz[i][j] * (((bit >> j) & 1 ) ? -1 : 1);
            }
            pq.push(tmp);
        }

        ll cand = 0;
        for (int i = 0; i < m; ++i) {
            cand += pq.top();
            pq.pop();
        }
        ans = max(cand, ans);
    }

    cout << ans << endl;
}

Measured memory_bytes: 888
void main() {
	auto ip = readAs!(int[]), K = ip[0], X = ip[1];
	if(K*500 >= X) writeln("Yes");
	else writeln("No");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
while True:
    a,b = map(int,input().split())
    
    if a == 0 and b == 0:
        break
    for i in range(a):
        if i == 0 or i == a-1:
            print(b*'#')
            
        else:
            print('#' + (b-2)*'.' + '#')
            
    print()        


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

int fanc(int k){
  int ans=1;
  for(int i=1; i<k; i++){
    ans *= i;
  }
  
  return ans;
}

int main(){
  int n;
  cin >> n;
  vector<int> p(n),q(n),a(n,1),b(n,1);
  int pos1=0,pos2=0;
  
  for(int i=0; i<n; i++){
    cin >> p.at(i);
  }
  for(int i=0; i<n; i++){
    cin >> q.at(i);
  }
  
  for(int i=0; i<n; i++){
    int x = fanc(n-i);
    int y = 0;
    for(int j=0; j<p.at(i); j++){
      y += a.at(j);
    }
	pos1 += (y-1)*x;
    a.at(p.at(i)-1) = 0;
  }
  
  pos1++;
  
  for(int i=0; i<n; i++){
    int x = fanc(n-i);
    int y = 0;
    for(int j=0; j<q.at(i); j++){
      y += b.at(j);
    }
	pos2 += (y-1)*x;
    b.at(q.at(i)-1) = 0;
  }
  
  pos2++;
  
  int ans = abs(pos1 - pos2);
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a, x[52] = {};
    ll d[52][2503] = {1}, z = 0;
    cin >> n >> a;
    for (int i = 1; i <= n; i++) cin >> x[i];
    for (int i = 1; i <= n; i++) {
        for (int j = n; j; j--) {
            for (int k = x[i]; k <= 2500; k++) {
                d[j][k] += d[j - 1][k - x[i]];
            }
        }
    }
    for (int i = 1; i <= n; i++) z += d[i][i * a];
    cout << z;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int a, b;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b;
	cout << (a * b - a - b + 1) << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    string s;
    cin >> s;
    repi(i, s){
        if(*i == '9') 
            cout << 1;
        else if(*i == '1')
            cout << 9;
        else 
            cout << *i;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a,n) a, a + n
#define prtarr(n,len) {for(int i=0;i<len;i++) cout<<n[i]<<" ";}

using namespace std;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;
using namespace std;

double d,t,s;
int main() {
    //freopen("input.txt", "r", stdin) ;
    //freopen("output.txt", "w", stdout) ;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    cin>>d>>t>>s;
    double time=d/s;
    string s=(time<=t) ? "Yes":"No";
    cout<<s;
    return 0;
}




Measured memory_bytes: 3744
#include <iostream>
#include <string>
using namespace std;
int main() {
    ios::sync_with_stdio(false);

    int n; cin >> n;
    int seq[100];
    for (int i=0; i<n; ++i) {
        cin >> seq[i];
    }

    for (int i=0; i<n; ++i) {
        int key = seq[i];
        int j;
        for (j=i; j>=1; --j) {
            seq[j] = seq[j-1];
            if (key >= seq[j]) {
                break;
            }
        }
        seq[j] = key;

        //trace:start
        for (int k=0; k<n; ++k) {
            if (k == 0) {
                cout << seq[k];
            } else {
                cout << " " << seq[k];
            }
        }
        cout << endl;
        //trace:end
    }

    return 0;
}

Measured memory_bytes: 1196
#include <stdio.h>
#define NOT_FOUND -1


int linerSearch(int,int,int *);
int main(){
  int A[10000];
  int a,i,b,n,n2,n3,count = 0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);

  scanf("%d",&n2);
  for(i=0;i<n2;i++){scanf("%d",&b);
 
 
    a = linerSearch(b,n,A);
    if(a != NOT_FOUND)count++;
    else continue;
  } printf("%d\n",count);
  return 0;
 
}

int linerSearch(int key,int n,int A[]){
  int i=0;
  
  A[n]=key;
  while(A[i]!=key){
    i++;
    if(i==n)return NOT_FOUND;
  }
  return i;
}



Measured memory_bytes: 2052
#include<stdio.h>

int main(void){
    long long N,A,B,f;

    scanf("%lld %lld %lld",&N,&A,&B);
    if(N%(A+B)<=A)
        f=N%(A+B);
    else
        f=A;
    printf("%lld",(N/(A+B))*A + f);
    return 0;
}

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define        sqr(a)       ((a)*(a))
//int dx[] = {0,1,0,-1};
//int dx[] = {0,1,0,-1};
//int dy[] = {-1,0,1,0};

//   cout<<std::setprecision(12)<<
struct dat
{
    int k,b[100],p;
};
int main()
{
    int i,j,l,m,n,q;

    cin >> n >> m;
    dat bul[m+10];
    for(i=0;i<m;i++)
    {
        cin >> bul[i].k;

        for(j=0;j<bul[i].k;j++)
        {
            cin >> bul[i].b[j];
        }

    }
    for(i=0;i<m;i++)cin>>bul[i].p;

    int ttl = (1<<n),mrk[n+10],cnt=0,ekn=0;

    for(i=0;i<ttl;i++)
    {
        //cout << i << endl;
        memset(mrk,0,sizeof mrk);

        for(j=0;j<n;j++)
        {
            if(i & (1<<j))
            {
                //cout << i << " " <<j << endl;
                mrk[j] = 1;
            }
        }
        ekn = 0;
        for(l=0;l<m;l++)
        {
            int cn = 0;
            for(q = 0;q < bul[l].k;q++)
            {
                if(mrk[bul[l].b[q]-1])cn++;
            }

            if(cn%2 == bul[l].p)ekn++;
        }
       // cout<<ekn<<" "<<m<<endl;
        if(ekn == m)cnt++;

    }

    cout << cnt << endl;
}


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

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

template<typename has_less>
using ordered_set =
tree<has_less,
	null_type,
	less<has_less>,
	rb_tree_tag,
	tree_order_statistics_node_update>;
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define F first
#define S second
#define ALL(v) v.begin(),v.end()
#define fast_cin() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define lc (sidx * 2)
#define rc (lc + 1)

typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

bool bit(int n, int i) { return (n >> i) & 1; }
int ceil(int a, int b) { return ceil(((ld)a) / b); }

int faltu;

const int mod = 1e9+7;
const ll inf = 5e18;
const int N = 2e5 + 100;

int h, w, n;
pii a[N];

bool cp(pii a, pii b) {
	if(a.F == b.F) {
		return a.S < b.S;
	}
	return a.F < b.F;
}

int main()
{
	fast_cin();
	srand(time(0));

	cin >> h >> w >> n;
	map <pii, int> mp;
	for(int i = 1; i <= n; i++) {
		cin >> a[i].F >> a[i].S;
		mp[{a[i].F, a[i].S}] = 1;
	}
	sort(a + 1, a + n + 1, cp);
	int x = 1, y = 1, ans = 0;
	int idx = 1;
	while(true) {
		if(idx <= n and a[idx].F == x and a[idx].S <= y) {
			cout << ans << endl;
			return 0;
		}
		while(idx <= n and a[idx].F == x) {
			idx++;
		}
		ans++;
		if(mp.find({x + 1, y}) != mp.end() or x == h) {
			cout << ans << endl;
			return 0;
		} else {
			x++;
			if(mp.find({x, y + 1}) == mp.end() and y < w) {
				y++;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 16384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,v,b,w,t;
    scanf("%lld%lld%lld%lld%lld",&a,&v,&b,&w,&t);
    if(b>a){
       if(a+v*t>=b+w*t)
          printf("YES\n");
       else
          printf("NO\n");
    }
    else{
        if(a-v*t<=b-w*t)
          printf("YES\n");
        else
          printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 3764
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    n = I()
    a = LI()
    even = False
    if n % 2 == 0:
        even = True
    N = n
    ans = []
    if even:
        # [6, 4, 2, 1, 3, 5]
        while N > 1:
            ans.append(a[N-1])
            N = N - 2
        N = 1
        while N < n:
            ans.append(a[N-1])
            N = N + 2
    else:
        # [5, 3, 1, 2, 4]
        while N > 0:
            ans.append(a[N-1])
            N = N - 2
        N = 2
        while N <= n:
            ans.append(a[N-1])
            N = N + 2
    for a in ans:
        print(a, end=' ')
    print()

main()



Measured memory_bytes: 27620
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[][] c = new int[k][];
		
		for(int i = 0; i < k; i++) {
			String s = sc.next();
			String[] ns = s.split(",");
			c[i] = new int[]{Integer.parseInt(ns[0]) - 1, Integer.parseInt(ns[1]) - 1};
		}
		int[] res = new int[n];
		for(int i = 0; i < n; i++) {
			int ret = i;
			for(int j = 0; j < k; j++) {
				for(int l = 0; l < 2; l++) {
					if(c[j][l] == ret) {
						ret = c[j][(l + 1) % 2];
						break;
					}
				}
			}
			res[ret] = i;
		}
		for(int i = 0; i < n; i++) {
			System.out.println(res[i] + 1);
		}
	}
}

Measured memory_bytes: 17208
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair

int main(void)
{
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    
    ll ret = 100000;
    while(n--) {
        ret *= 1.05;
        ret = ((ret + 999) / 1000) * 1000;
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 1188
#include <iostream>
using namespace std;
int main() {
  long long n;
  long long a, b, c;
  long long m = 0;
  cin >> n;
  for (long long a = 1; a < n; ++a) {
    for (long long b = 1; b < n; ++b) {
      long long p = a * b;
      if (n <= p) {
        break;
      }
      int c = n - p;
      m++;
    }
  }
  cout << m << endl;

  return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
const int maxn=200005;
typedef long long ll;
int n,m;
char s[maxn];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	ll ans=0,cnt=0;
	for(int i=n;i>=1;i--)
	{
		if(s[i]=='A')
			ans+=cnt;
		else if(s[i]=='C')
		{
			if(s[i-1]=='B')cnt++;
			else cnt=0;
		}
		else
		{
			if(s[i+1]=='C');
			else cnt=0;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;

// 最大公約数
lint gcd(lint a, lint b) {
    // 引数の一方が 0 なら他方の値を返す
    return b ? gcd(b, a%b) : a;
}

/****************** データ構造 ******************/
// セグメントツリー (点変更・区間クエリ)
template <typename monoid>
struct segment_tree {
    using M = monoid;
    using T = typename M::value_type;

    size_t sz;
    vector<T> x;

    segment_tree(size_t n = 0) {
        sz = 1;
        while (sz < n) sz *= 2;
        x.assign(sz * 2, M::id());
        initialize();
    }

    template <typename iterator>
    segment_tree(iterator first, iterator last) {
        sz = 1;
        size_t n = distance(first, last);
        while (sz < n) sz *= 2;
        x.assign(sz * 2, M::id());
        copy(first, last, x.begin() + sz);
        initialize();
    }

    void fill(const T& val) {
        std::fill(x.begin() + sz, x.end(), val);
        initialize();
    }

    void initialize() {
        for (int i = (int)sz - 1; i >= 1; --i) {
            x[i] = M::op(x[i * 2 + 0], x[i * 2 + 1]);
        }
    }

    T accumulate(size_t l, size_t r) const {  // [l, r)
        T al = M::id(), ar = M::id();
        for (l += sz, r += sz; l < r; l /= 2, r /= 2) {
            if (l & 1) al = M::op(al, x[l++]);
            if (r & 1) ar = M::op(x[--r], ar);
        }
        return M::op(al, ar);
    }

    void update(size_t i, const T &val) {
        x[i += sz] = val;
        while (i > 1) {
            x[i / 2] = M::op(x[i], x[i ^ 1]);
            i /= 2;
        }
    }

    T operator[](size_t i) const { return x[sz + i]; }
};

template <typename T>
struct gcd_monoid {
    using value_type = T;
    static constexpr T id() { return 0; }
    static T op(const T &a, const T &b) { return gcd(a, b); }
};
template <typename value_type>
using rgq = segment_tree<gcd_monoid<value_type>>;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n);
    repeat (i, n) cin >> a[i];
    
    rgq<int> st(n);
    repeat (i, n) st.update(i, a[i]);
    cout << st.accumulate(0, n) << endl;
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main() {

    int n, w;
    scanf("%d", &n);

    int arr[n];
    int mysum = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &w);
        mysum += w;
        arr[i] = w;
    }

    int mindata = abs(arr[0] - (mysum - arr[0]));

    int temp = 0;
    for (int j = 0; j < n; j++) {
        temp += arr[j];
        if (mindata > abs(temp - (mysum - temp))) {
            mindata = abs(temp - (mysum - temp));
        }

    }
    printf("%d", mindata);


    return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <math.h>
using namespace std;

long long int calcModPow(long long int a, long long int n, long long int m) {
	if (n == 0){
		return 1 % m;
	}
    if (n == 1){
        return a % m;
    }

    if (n % 2 == 1){
        return (a * calcModPow(a, n - 1, m)) % m;
    }

    long long int t = calcModPow(a, n / 2, m);
    return (t * t) % m;
}

int main()
{
	string S;
	int mod = 0, res = 0;
	vector<int> modEnd, n;

	cin >> S;
	
	for(int i=0; i<S.length(); i++){
		int tmp = S[S.length()-1-i] - '0';
		mod = (mod + calcModPow(10, i, 2019) * tmp % 2019)%2019;

		modEnd.push_back(mod);
	}

	for(int i=0; i<2020; i++){
		n.push_back(0);
	}


	for(int i=0; i<S.length(); i++){
		n[modEnd[i]]++;
	}

	res += (n[0]+1)*n[0]/2;

	for(int i=1; i<2020; i++){
		res += n[i]*(n[i]-1)/2;
	}
	
	cout << res;

	return 0;
	
}

Measured memory_bytes: 4412