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

int main()
{
  int X, Y, c[15][15], dp[15][16];

  while(cin >> X >> Y, X) {
    fill_n( *dp, 15 * 16, 0);
    for(int i = 0; i < X; i++) {
      dp[0][i] = 1;
    }


    for(int i = 0; i < Y; i++) {
      for(int j = 0; j < X; j++) {
        cin >> c[i][j];
      }
    }
    int ret = 0;
    for(int i = 0; i < Y; i++) {
      for(int j = 0; j < X; j++) {
        if(c[i][j] == 0) {
          for(int k = -1; k <= 1; k++) {
            if(j + k < 0 || j + k >= X) continue;
            if(i + 1 >= Y) {
              if(k == 0) ret += dp[i][j];
            } else {
              if(c[i + 1][j + k] == 2 && k != 0) continue;
              dp[i + 1][j + k] += dp[i][j];
            }
          }
        } else if(c[i][j] == 1) {
          continue;
        } else {
          if(i + 2 >= Y) ret += dp[i][j];
          else dp[i + 2][j] += dp[i][j];
        }
      }
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 1160
# C - Traveling
def can_travel(N):

	last_t, last_x, last_y = 0, 0, 0
	
	for i in range(N):
		t, x, y = map(int, input().split())
		distnace = abs(x - last_x) + abs(y - last_y)
		time = t - last_t
		
		if distnace > time:
			return False
		elif (time - distnace) % 2 == 1:
			return False
	
	return  True
		

N = int(input())

if can_travel(N):
	print('Yes')
else:
	print('No')


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
	int n, tmp2 = 0;
	char tmp1;
	bool array[4][13] = {};
	int mark[64] = {};
	mark['S' - 64] = 0;
	mark['H' - 64] = 1;
	mark['C' - 64] = 2;
	mark['D' - 64] = 3;
	char cards[4] = { 'S', 'H', 'C', 'D' };

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> tmp1;
		cin >> tmp2;
		array[mark[tmp1-64]][tmp2-1] = true;
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			if (array[i][j] != true) { cout << cards[i] << " " << j + 1 << endl; }
		}
	}

	cin >> n;
	return 0;
}


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

int main(){
  int n;
  int num[100];
  cin >> n;
  for(int i=0;i<n;++i){
      cin >> num[i];
      cout << (i==0?"":" ") << num[i];
  }
  cout << endl;
  
  for(int i=1;i<n;++i){
      int key = num[i]; //現在の値
      int j = i - 1;    //iより左の値を全て確認
      while(j>=0 && num[j] > key){
          num[j+1] = num[j];
          --j;
      }
      num[j+1] = key;
      for(int j=0;j<n;++j) cout << (j==0?"":" ") << num[j];
      cout << endl;
    }


  return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define si set <ll>
#define vi vector <ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define ld long double
#define rall(a) (a).rbegin(),(a).rend()

ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}


void solve()
{
	vi v(5);
	rep(i,0,5) 
	{
		cin>>v[i];
		if(!v[i]) 
		{
			cout<<i+1<<"\n";
			return;
		}
	}
}

int main()       
{
	fastio
	ll t=1;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 3564
#include <stdio.h>
#include <string.h>
#define MAX 100000000

char str[14];
char H[MAX];

int find(void);
void insert(void);
int getChar(char);
int getkey(void);

int main(){
  int i,j,n;
  char a[7];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s%s",a,str);
    if(a[0]=='i'){
      insert();
    }
    else if(a[0]=='f'){
      if(find())printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}

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

int getkey(){
  int sum=0, b=1,i;
  for(i=0;i<strlen(str);i++){
    sum+=b*(getChar(str[i]));
    b*=5;
  }
  return sum;
}

int find(){
  int key = getkey();
  if(H[key])return 1;
  else return 0;
}

void insert(){
  int sum;
  sum=getkey();
  H[sum]=1;
}

Measured memory_bytes: 10088
#include<iostream>
#include<iomanip>
#include<sstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<numeric>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
const double PI = atan(1.0) * 4 ;
double eps = 1e-10 ;

template <typename T>
void out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
}

template<typename T>
string ntos( T i ) {
  ostringstream s ;
  s << i ;
  return s.str() ;
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  double x = 1.0,y = 0.0, rad = 0 ;
  while(cin >> n){
    if(n == -1){
      break;
    }
    x = 1.0,y = 0.0, rad = 0;
    rep(i,n-1){
      rad += PI / 2.0;
      x += cos(rad) ;
      y += sin(rad) ;
      rad = atan2(y,x) ;
    }
    cout << x << endl << y << endl ;
  }
  return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<62);
int main() {
    vec h = {2, 4, 5, 7, 9};
    cin>>N;
    N = N%10;
    S = "pon";
    if(N == 3){
        S = "bon";
    }else{
        for(ll v : h) if(N == v) S = "hon";
    }
    cout<<S<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<utility>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	string a;
	cin>>a;
	if(a=="SUN")
		cout<<7<<endl;
	else if(a=="MON")
		cout<<6<<endl;
	else if(a=="TUE")
		cout<<5<<endl;
	else if(a=="WED")
		cout<<4<<endl;
	else if(a=="THU")
		cout<<3<<endl;
	else if(a=="FRI")
		cout<<2<<endl;
	else
		cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:33554432")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>
#include <math.h>

using namespace std;

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

const int MAXN = 2e3 + 20;

void solve() {

    int n, k;
    cin >> n >> k;

    vector<ll> vec;

    for (int i = 0; i < n; ++ i){
        ll crr;
        cin >> crr;
        vec.push_back(crr);
    }

    sort(vec.rbegin(), vec.rend());


    ll answr = 0;
    for (int i = k; i < n; ++ i){
        answr += vec[i];
    }

    cout << answr;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);

    solve();
}

Measured memory_bytes: 2420
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0
for i in range(n-1,-1,-1):
    # i+1の討伐
    if a[i+1] < b[i]:
        count += a[i+1]
        b[i] -= a[i+1]
        a[i+1] = 0
    else:
        count += b[i]
        a[i+1] -= b[i]
        b[i] = 0
    # iの討伐
    if a[i] < b[i]:
        count += a[i]
        b[i] -= a[i]
        a[i] = 0
    else:
        count += b[i]
        a[i] -= b[i]
        b[i] = 0
print(count)


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

using namespace std;

void solve(int N) {
  vector<int> cand({1, 2, 4, 8, 16, 32, 64});
  cout << *(lower_bound(cand.begin(), cand.end(), N + 1) - 1) << endl;
}


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

  int N;
  cin >> N;

  solve(N);

  return 0;
}


Measured memory_bytes: 3608
INF = 10**9

N, K = map(int, input().split())
x_list = [int(i) for i in input().split()]
for i in range(N):
    if x_list[i] >= 0:
        T = i
        break
else:
    print(abs(x_list[-K]))
    exit()
min_take_time = INF
for i in range(K+1):
    if T-K+i < 0 or T+i>N:
        continue
    if x_list[T-K+i] *  x_list[T+i-1] <= 0:
        take_time = min(abs(x_list[T-K+i]), abs(x_list[T+i-1])) * 2 + max(abs(x_list[T-K+i]), abs(x_list[T+i-1]))
    else:
        take_time = max(abs(x_list[T-K+i]), abs(x_list[T+i-1]))
    min_take_time = min(min_take_time, take_time)


print(min_take_time)

Measured memory_bytes: 14664
#include <stdio.h>
#include <iostream>
using namespace std;

int n;
struct Edge
{
    int num;
    int next;
}edge[250005];
int tot,last[100005];
int fa[100005];
int d[100005];
bool used[100005];
int num[100005];

void Add(int i,int j)
{
    tot++;
    edge[tot].num=j;
    edge[tot].next=last[i];
    last[i]=tot;
}

void dfs(int i,int deep)
{
    d[i]=deep;
    used[i]=1;
    int sum=0;
    for (int k=last[i];k!=0;k=edge[k].next)
        {
        int v=edge[k].num;
        if (used[v]!=0) continue;
        fa[v]=i;
        dfs(v,deep+1);
        sum=sum+num[v];
        }
    num[i]=sum+1;
}

void work()
{
    int p=d[n]/2+1;
    int u=n;
    while (d[u]!=p) u=fa[u];
    //printf ("%d %d\n",u,d[n]);
    if (d[n]%2==1)
        {
        if (num[u]-(d[n]-d[u]+1)>=num[1]-num[u]-d[u]) printf ("Snuke\n");
        else printf ("Fennec\n");
        }
    else
        {
        if (num[u]-(d[n]-d[u]+1)>num[1]-num[u]-d[u]) printf ("Snuke\n");
        else printf ("Fennec\n");
        }
}

int main()
{
    scanf ("%d",&n);
    for (int i=1;i<n;i++)
        {
        int a,b;
        scanf ("%d %d",&a,&b);
        Add(a,b);
        Add(b,a);
        }
    dfs(1,0);
    work();
}


Measured memory_bytes: 9728
#include <bits/stdc++.h>
#define F first
#define S second
#define INF 1 << 21
using namespace std;
typedef struct{
  int to;int cost;
}Edge;
typedef pair<int,int> P;
priority_queue<P, vector<P>, greater<P> > pq;
int main(){
  int d[11111];
  int n,m;
  int ans;
  char ch;
  int a,b,c,z;
  int st,go,hasira,money;
  vector<Edge> G[111];
  cin >> n;
  cin >> m;
  fill(d,d+m,INF);
  for(int i=0;i<m;i++){
    cin >> a >> ch >> b >> ch >> c >> ch >> z;
    G[a].push_back( (Edge){ b,c});
    G[b].push_back( (Edge){ a,z});
  }
  
  cin >> st >> ch >> go >> ch >> money >> ch >> hasira;
  d[st]=0;//出発地点の自明
  pq.push(P(0,st));
  
  while(!pq.empty()){
    P p=pq.top();
    pq.pop();
    int v=p.S;//使っていないところからの最短距離について調べる
    if(d[v]<p.first)continue; //すでに今までのが小さいならみなくてもいい
    for(int i=0;i<G[v].size()/*そこからつながっている道の数わかっちゃうやつ*/;i++){
      Edge e=G[v][i];
      if(d[e.to] > d[v] + e.cost){
	d[e.to] = d[v] + e.cost;
	pq.push(P(d[e.to],e.to));
      }
    }
  }

  ans=d[go];
  
  /*帰り道*/
  fill(d,d+m,INF);

  d[go]=0;//出発地点の自明
  pq.push(P(0,go));
  
  while(!pq.empty()){
    P p=pq.top();
    pq.pop();
    int v=p.S;//使っていないところからの最短距離について調べる
    if(d[v]<p.first)continue; //すでに今までのが小さいならみなくてもいい
    for(int i=0;i<G[v].size()/*そこからつながっている道の数わかっちゃうやつ*/;i++){
      Edge e=G[v][i];
      if(d[e.to] > d[v] + e.cost){
	d[e.to] = d[v] + e.cost;
	pq.push(P(d[e.to],e.to));
      }
    }
  }
  ans+=d[st];
  
  cout << money-ans-hasira << endl;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef pair<int,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
struct Point{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x = _x;
        y = _y;
    }
    Point operator + (Point p){
        return Point(x+p.x,y+p.y);
    }
  
    Point operator - (Point p){
        return Point(x-p.x,y-p.y);
    }
  
    Point operator * (double k){
        return Point(k*x,k*y);
    }
  
    Point operator / (double k){
        return Point(x/k,y/k);
    }
 
    bool operator<(const Point &p)const{
        return x!=p.x?x<p.x:y<p.y;
    }
  
};
double dot(Point p, Point q){
    return p.x*q.x+p.y*q.y;
}
  
double cross(Point p,Point q){
    return p.x*q.y-q.x*p.y;
}
  
double norm(Point p){
    return p.x*p.x+p.y*p.y;
}
  
double pabs(Point p){
    return sqrt(norm(p));
}
typedef vector<Point> Polygon;
struct Line : Polygon{
    Line(){}
    Line(Point p,Point q){
        PB(p);
        PB(q);  
    }
};
struct Circle{
    Point p; //中心点
    double r; //半径
    Circle(){}
    Circle(Point _p,double _r){
        p = _p;
        r = _r;
    }
};
int ccw(Point a,Point b,Point c){
    b = b-a;
    c = c-a;
    if(cross(b,c) > 0)return +1; //a→b で反時計に折れてc ccw
    if(cross(b,c) < 0)return -1; //a→b で時計に折れてc ccw
    if(dot(b,c) < 0)return +2; // c--a--b;
    if(pabs(b)<pabs(c))return -2; //a--b--c
    return 0; //a--c--b
}
bool intersectSS(Line l,Line m){
    //lとmが交差してるかどうか
    return (ccw(l[0],l[1],m[0])*ccw(l[0],l[1],m[1])<=0)&&
            (ccw(m[0],m[1],l[0])*ccw(m[0],m[1],l[1])<=0);
}
 
double TriangleArea(Point a,Point b,Point c){
    b = b - a;
    c = c - a;
    return cross(b,c)*0.5;
}
 
double VertexArea(Polygon v){
    double subArea = 0.0;
    rep(i,v.size()-1){
        subArea += TriangleArea(v[0],v[i],v[i+1]);
    }
    return subArea;
}
 
Point crosspoint(Line l,Line m){
    if(intersectSS(l,m) == false)return Point(INF,INF);
    return m[0]+(m[1]-m[0])*cross(l[1]-l[0],l[1]-m[0])/cross(l[1]-l[0],m[1]-m[0]);
}
 
int main(){
    int N;
    cin >> N;
    Polygon v;
    while(N--){
    	double x,y;
    	cin >> x >> y;
    	v.PB(Point(x,y));
    }
    printf("%.1lf\n",VertexArea(v));
    return 0;
}

Measured memory_bytes: 1256
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C
import Data.Maybe (fromJust)
import Data.List (sort)
import Control.Monad (forM, replicateM)

getInts :: IO [Integer]
getInts = map (fst . fromJust . C.readInteger) <$> C.words <$> B.getLine

rsort :: (Ord a) => [a] -> [a]
rsort = reverse . sort

md = 1000000000 + 7 :: Integer

powm :: Integer -> Integer -> Integer
powm _ 0 = 1
powm x y = powm (x*x `mod` md) (y `div` 2) * (if y `mod` 2== 0 then 1 else x) `mod` md

inv :: Integer -> Integer
inv x = powm x (md - 2) :: Integer

choose :: Integer -> Integer -> Integer
choose n 0 = 1
choose n m = (choose (n-1) (m-1)) * n * (inv m) `mod` md

main :: IO ()
main = do
    [n, m, k] <- getInts
    let val = (m * m * (sum n) + n * n * sum(m))`mod` md
    print $ val * choose (n*m-2) (k-2) `mod` md
    where
        sum w = (w * w * (w+1) `div` 2 - w * (w+1) * (2*w + 1) `div` 6) `mod` md


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

using namespace std;

char s[100010];

int main()
{
    s[0] = '0';
    scanf("%s", s + 1);
    int n = strlen(s);
    int i = 0, j = n - 1;
    if(s[1] != '1')
    {
        printf("-1");
        return 0;
    }
    for(; i < j; i++, j--)
    {
        if(s[i] != s[j])
        {
            printf("-1");
            return 0;
        }
    }
    int ult = 1;
    for(i = 1; i < n - 1; i++)
    {
        printf("%d %d\n", ult, i + 1);
        if(s[i] == '1')
            ult = i + 1;
    }
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
using namespace std;

#define PI 4*atan(1);

int main(){
  int n, a, b, c;
  vector<int> ans;
  ans.push_back(1);
  cin >> n;
  if(n == 2){
    cin >> a >> b;
    for(int i = 2; i < max(a, b); i++){
      if(a % i == 0 && b % i == 0){
        ans.push_back(i);
      }
    }
    for(int i = 0; i < ans.size(); i++){
      cout << ans[i] << endl;
    }
  }else if(n == 3){
    cin >> a >> b >> c;
    for(int i = 2; i < max(max(a, b), c); i++){
      if(a % i == 0 && b % i == 0 && c % i == 0){
        ans.push_back(i);
      }
    }
    for(int i = 0; i < ans.size(); i++){
      cout << ans[i] << endl;
    }
  }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb emplace_back
typedef pair<int,int> pi;

int n, x, y, ans[2005], dist[2005];
vector<int> g[2005];

int main() {
	ios_base::sync_with_stdio(0); 
	cin.tie(0);
	cin >> n >> x >> y;
	for (int i = 1; i <= n; ++i) {
		g[i].pb(i + 1);
		g[i + 1].pb(i);
	}
	g[x].pb(y);
	g[y].pb(x);
	for (int i = 1; i <= n; ++i) {
		queue<int> q;
		memset(dist, -1, sizeof dist);
		dist[i] = 0;
		q.emplace(i);
		while (q.size()) {
			int x = q.front();
			q.pop();
			for (auto v: g[x]) {
				if (dist[v] != -1) continue;
				dist[v] = dist[x] + 1;
				q.emplace(v);
			}
		}
		for (int j = 1; j <= n; ++j) {
			if (i == j) continue;
			++ans[dist[j]];
		}
	}
	for (int i = 1; i < n; ++i) cout << ans[i] / 2 << '\n';
	return 0;
}


Measured memory_bytes: 3728
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val s = readLine()!!
    val k = readLong()

    val runLengthS = runLengthEncode(s)
    if (runLengthS.size == 1) {
        println(s.length * k / 2)
        return
    }

    var ansForS = 0
    for (run in runLengthS) {
        ansForS +=  run.length / 2
    }

    val runLengthSS = runLengthEncode(s + s)
    var ansForSS = 0
    for (run in runLengthSS) {
        ansForSS += run.length / 2
    }

    val diff = ansForSS - ansForS
    println(ansForS + diff * (k - 1))
}

data class RunLength<T>(val value: T, var length: Int)

/** O(s.length) */
//fun runLengthEncode(s: String): List<RunLength<Char>> {
//    if (s.isEmpty()) return emptyList()
//
//    val runLengthList = mutableListOf<RunLength<Char>>()
//    var currentChar = s.first()
//    var length = 1
//    for (c in s.substring(1)) {
//        if (c == currentChar) {
//            length++
//        } else {
//            runLengthList += RunLength(currentChar, length)
//            currentChar = c
//            length = 1
//        }
//    }
//    runLengthList += RunLength(currentChar, length)
//
//    return runLengthList
//}

fun runLengthEncode(s: CharSequence): List<RunLength<Char>> = s.fold(mutableListOf<RunLength<Char>>()) { acc, value ->
    if (acc.isNotEmpty() && acc.last().value == value) {
        acc.last().length++
    } else {
        acc += RunLength(value, 1)
    }
    acc
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 33672
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] s = new String[h];
		for (int i = 0; i < h; i++) {
			s[i] = sc.next();
		}
		int[][] u = new int[h][w];
		int[][] r = new int[h][w];
		int[][] d = new int[h][w];
		int[][] l = new int[h][w];
		for (int i = 0; i < h; i++) {
			int tmp = 0;
			for (int j = 0; j < w; j++) {
				if (s[i].charAt(j) == '.') {
					tmp++;
				} else {
					tmp = 0;
				}
				l[i][j] = tmp;
			}
		}
		for (int i = 0; i < h; i++) {
			int tmp = 0;
			for (int j = w - 1; j >= 0; j--) {
				if (s[i].charAt(j) == '.') {
					tmp++;
				} else {
					tmp = 0;
				}
				r[i][j] = tmp;
			}
		}
		for (int i = 0; i < w; i++) {
			int tmp = 0;
			for (int j = 0; j < h; j++) {
				if (s[j].charAt(i) == '.') {
					tmp++;
				} else {
					tmp = 0;
				}
				u[j][i] = tmp;
			}
		}
		for (int i = 0; i < w; i++) {
			int tmp = 0;
			for (int j = h - 1; j >= 0; j--) {
				if (s[j].charAt(i) == '.') {
					tmp++;
				} else {
					tmp = 0;
				}
				d[j][i] = tmp;
			}
		}
		int ans = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				ans = Math.max(ans, u[i][j] + r[i][j] + d[i][j] + l[i][j] - 3);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 118572
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
	int N;
	int n;
	while(~scanf("%d", &N))
		for(n = 1; n * n <= N; n++)
			if((n+1)*(n+1) > N)
			printf("%d\n", n*n);
}

Measured memory_bytes: 128
n,m = list(map(int, input().split()))

box = [1] * (n+1) 
redbox = [False] * (n+1) 
redbox[1] = True
for _ in range(m):
    x,y = list(map(int, input().split()))
    box[x]-=1
    box[y]+=1
    if redbox[x]:
        redbox[y] = True
    if box[x]==0:
        redbox[x] = False
#    print(box)
#    print(redbox)
print(sum(map(int, redbox[1:])))

Measured memory_bytes: 5492
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int main() {
	int N;
	cin >> N;
	vector<int>A(N), B(N), C(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	for (int i = 0; i < N; ++i) {
		cin >> B[i];
	}
	for (int i = 0; i < N; ++i) {
		cin >> C[i];
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());
	ll res = 0;
	for (int i = 0; i < N; ++i) {
		ll na = distance(A.begin(), lower_bound(A.begin(), A.end(), B[i]));
		ll nc = distance(upper_bound(C.begin(),C.end(),B[i]),C.end());
		res += na * nc;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1408
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    string s,t;
    cin>>s>>t;
    vi idx[26];
    rep(i,0,sz(s)-1){
        idx[s[i]-'a'].pb(i);
    }
    ll ans=0;
    ll last=-1;
    rep(i,0,sz(t)-1){
        ll curr=t[i]-'a';
        if(sz(idx[curr])==0){
            cout<<"-1";
            return;
        }
        ll ii=upper_bound(all(idx[curr]),last)-idx[curr].begin();
        if(ii==sz(idx[curr])){
            ans+=sz(s);
            last=-1;
            i--;
        }
        else{
            last=idx[curr][ii];
        }
    }
    if(last!=-1) ans+=last;
    cout<<ans+1;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll MOD = 1e9 + 7;
ll dp[10010][2][100];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s; cin >> s;
	ll m; cin >> m;
	
	vvl dp(2,vl(m));
	dp[0][0] = 1;

	FOR(i,0,sz(s)) {
		vvl ndp(2,vl(m));
		FOR(lt,0,2) FOR(j,0,m) {
			FOR(d,0,10) {
				if (!lt && d > s[i]-'0') continue;
				ll nlt = lt || (d < s[i]-'0');
				ll nj = (j + d) % m;
				ndp[nlt][nj] = (ndp[nlt][nj] + dp[lt][j]) % MOD;
			}
		}
		dp = ndp;
	}
	
	ll res = (dp[0][0] + dp[1][0] + MOD-1) % MOD;
	cout << res << endl;
}



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

using namespace std;

int main(){
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;

    int dx = tx-sx;
    int dy = ty-sy;

    cout<<string(dy,'U')<<string(dx,'R');
    cout<<string(dy,'D')<<string(dx,'L');
    cout<<'L'<<string(dy+1,'U')<<string(dx+1,'R')<<'D';
    cout<<'R'<<string(dy+1,'D')<<string(dx+1,'L')<<'U'<<endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		
		boolean[] visits = new boolean[100000];
		Arrays.fill(visits, false);
	
		int[] buttons = new int[n];
		for (int i = 0; i < buttons.length; i++) {
			buttons[i] = scanner.nextInt();
		}
		
		int now = 0;
		int ans = 0;
		while(true){
			ans++;
			if (visits[now]) {
				ans = -1;
				break;
			}else {
				visits[now] = true;
			}
			now = buttons[now]-1;
			if (now==1) {
				break;
			}
		}
		
		System.out.println(ans);
		
		
		
		
		scanner.close();
	}
}

Measured memory_bytes: 52840
#include <iostream>
#include <string>
using namespace std;
using ll = long long;

int main() {
    string S;
    ll K;
    cin >> S >> K;
    
    // K文字目までをチェック
    for (ll i = 0; i < K; ++i) {
        if (S[i] != '1') {
            // 1以外が出たら答え
            cout << S[i] << endl;
            return 0;
        }
    }
    
    // K文字目まで全部1 -> 1が答え
    cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

string s;

int main(){
	cin>>s;
	int ans=s.size();
	for(int i=0;i<s.size()-1;i++)
		if(s[i]!=s[i+1])
			ans=min(ans,max(i+1,s.size()-i-1));
		
	cout<<ans<<endl;
	return 0;
}

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

int main(int argc, const char * argv[]) {
    
    string A,B,C;
    cin >> A >> B >> C;
    
    int length_a = (int)A.size();
    int length_b = (int)B.size();
    
    if((A[(length_a-1)] == B[0]) && (B[(length_b-1)] == C[0])){
        cout << "YES";
    }else{
        cout << "NO";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef unsigned long long  ull;
typedef vector<int> vi;

struct pp{ll x,y;};

const int base = 1000*1000*1000;
const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
const int inf = (int)1e9;
const int mod = 1e9+7;
ll gcd (ll a, ll b) {
        while (b) {
            a %= b;
            swap (a, b);
        }
        return a;
}

/*
void quickSort(int left, int right) {
      int i = left, j = right;
      pp tmp;
      int pivot = a[(left + right) / 2].x;
      while (i <= j) {
            while (a[i].x < pivot)
                  i++;
            while (a[j].x > pivot)
                  j--;
            if (i <= j) {
                 swap(a[i],a[j]);
                  i++,j--;
            }
      };
    if (left < j)
            quickSort(left, j);
      if (i < right)
            quickSort(i, right);
}*/
ll binpow (ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a,res %= mod;
		a *= a,a %= mod;
		n >>= 1;
	}
	return res;
}
int main(){
    ll n,x;
    cin>>n;
    ll cnt=0;
    for(ll i=0;i<n;i++){
        cin>>x;
        cnt+=x%2;
    }
    if(cnt%2)cout<<"NO";
    else cout<<"YES";
}


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

int main() {
int N,P,W,G,Y;
  P=0;
  W=0;
  G=0;
  Y=0;
cin >>N;
  
rep(i,N){
  string S;
  cin>>S;
  
	if(S=="P"){
	P=1;
	}
	else if(S=="W"){
	W=1;
	}
    else if(S=="G"){
	G=1;
    }
    else if(S=="Y"){
	Y=1;
	}
  


}
if(P+W+G+Y==3){
  cout<<"Three"<<endl;
  }
  else if(P+W+G+Y==4){
  cout<<"Four"<<endl;
  }

}


Measured memory_bytes: 256
import java.util.Scanner;
import java.io.IOException;

class Main {
	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		double r = scan.nextDouble();
		String a = String.format("%.5f", r * r * Math.PI);
		String b = String.format("%.5f", (r * 2) * Math.PI);
		System.out.println(a + " " + b);
	}
}

Measured memory_bytes: 28292
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String str = sc.next();
      boolean[] a = new boolean[str.length()];
      if(str.matches("A[a-z]+C[a-z]+"))System.out.println("AC");
      else System.out.println("WA");
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	int n;
	cin >> n;
	int x = (n*100)/108;
	int a = (x*108)/100;
	int b = ((x+1)*108)/100;
	int c = ((x-1)*108)/100;
	if(a == n) {
		cout << x << endl;
	} else if (b == n) {
		cout << x+1 << endl;
	} else if (c == n) {
		cout << x-1 << endl;
	} else {
		cout << ":(" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
const double INF3 = 900000000000000;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()

struct edge { ll to, cap, rev; };

vector<edge>g[1010];
bool used[1010] = {0};
int v, e;

void add(ll from, ll to, ll cap) {
	g[from].push_back(edge { to, cap, (ll)g[to].size() });
	g[to].push_back(edge { from, (ll)0, (ll)g[from].size() - 1 });
}

ll dfs(ll v, ll t, ll f) {
	if (v == t)return f;
	used[v] = true;
	for (int i = 0;i < g[v].size();i++) {
		edge &e = g[v][i];
		if (!used[e.to] && e.cap > 0) {
			ll d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				g[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

ll max_flow(ll s, ll t) {
	ll flow = 0;
	for (;;) {
		fill(used, used + v, 0);
		ll f = dfs(s, t, INF2);
		if (f == 0)return flow;
		flow += f;
	}
}

int main() {
	cin >> v >> e;
	for (int i = 0;i < e;i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		add(a, b, c);
	}
	cout << max_flow(0, v - 1) << endl;
return 0;
}


Measured memory_bytes: 3284
#include <atcoder/fenwicktree>
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using namespace atcoder;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

signed main() {
  int n, q;

  cin >> n >> q;
  vector<int> a(n);
  fenwick_tree<lli> fen(n);
  rep(i, n) {
    cin >> a[i];
    fen.add(i, a[i]);
  }
  while (q--) {
    int t, a, b;
    cin >> t >> a >> b;
    if (t) {
      cout << fen.sum(a, b) << endl;
    } else {
      fen.add(a, b);
    }
  }

  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 12132
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A, B, C;
  cin >> A >> B >> C;
  
  if(A < C && C < B || B < C && C < A){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <fstream>
#include <stack>
#include <cstdlib>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define fst first
#define snd second
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ld long double

template < typename T>
T sqr(T x) {
	return x * x;
}

template < typename T>
T abs(T x) {
	return x > 0 ? x : -x;
}

//////////////////////////////////////////////////

const int maxn = 1e5+3;
vector < int > g[maxn];

int dfs(int v) {
	if (g[v].empty()) {
		return 0;
	}
	vector < int > f;
	for (auto to : g[v]) {
		f.pb(dfs(to));
	}
	sort(f.begin(), f.end());
	reverse(f.begin(), f.end());
	for (int i = 1; i < (int)f.size(); i++) {
		f[i] += i;
	}
	sort(f.begin(), f.end());
	return f.back() + 1;
}

int main() {
	//srand(time(NULL));
	#ifdef LOCAL	
		//gen();
		freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
		cout << endl << endl;
	#else
		//freopen("whats.in", "r", stdin);
		//freopen("whats.out", "w", stdout);
	#endif
	//check();
	
	ios_base::sync_with_stdio(false);
	
	int n;
	cin >> n;
	for (int i = 2; i <= n; i++) {
		int x;
		cin >> x;
		g[x].pb(i);
	}
	
	cout << dfs(1) << "\n";
	
	return 0;
}


Measured memory_bytes: 13568
from functools import lru_cache

@lru_cache(maxsize=10000)
def calc(n, k):
    # print(n, k)

    if n < 10:
        if k > 1:
            # print('1:return 0')
            return 0
        elif k == 1:
            # print('2:return ' + str(n))
            return n
        else:
            return 1

    else:
        if k == 0:
            # print('5:return ')
            return 1#calc(n // 10, k)
        else:
            # print('6:return ')
            return calc(n // 10, k - 1) * (n % 10) + calc(n // 10 - 1, k - 1) * (9 - n % 10) + calc(n // 10, k)

n = int(input())
k = int(input())

print(calc(n, k))


Measured memory_bytes: 3940
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
#include<string.h>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	rep(i, n - k) {
		if (a[i] < a[k + i]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

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

int main()
{
  int H,W;
  while(1){
    cin >>H>>W;
    if(H==0 && W==0){break;}
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        cout<<"#";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
line_0 = list(map(int, input().split()))
line_1 = list(map(int, input().split()))
line_2 = list(map(int, input().split()))
num = int(input())

is_open = [[False, False, False], [False, False, False], [False, False, False]]
for i in range(num):
    open_num = int(input())
    for j in range(3):
        if line_0[j] == open_num:
            is_open[0][j] = True
        if line_1[j] == open_num:
            is_open[1][j] = True
        if line_2[j] == open_num:
            is_open[2][j] = True

clear = "No"

if is_open[0] == [True, True, True]:
    clear = "Yes"
if is_open[1] == [True, True, True]:
    clear = "Yes"
if is_open[2] == [True, True, True]:
    clear = "Yes"

for i in range(3):
    if is_open[0][i] == is_open[1][i] == is_open[2][i] == True:
        clear = "Yes"

if is_open[0][0] == is_open[1][1] == is_open[2][2] == True:
    clear = "Yes"
if is_open[0][2] == is_open[1][1] == is_open[2][0] == True:
    clear = "Yes"

print(clear)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 
int sieve[10000005];

int main() {
  int n; cin >> n;
  for (int i=1; i<=n; i++) {
    for (int j=i; j<=n; j+=i) {
      sieve[j]++;
    }
  }  
  ll ans = 0;
  for (ll i=1; i<=n; i++) {
    ans += i*sieve[i];
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 42808
// Created by PRATEEK RANJAN
#include <bits/stdc++.h>
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long
const int mod = 1e9+7;

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n,m;
    cin>>n>>m;
    pair<int,int> arr[n],a[m];
    for(int i=0;i<n;i++){
        cin>>arr[i].first>>arr[i].second;
    }
    // for(int i=0;i<n;i++){
    //     cout<<arr[i].first<<" "<<arr[i].second<<"\n";
    // }
    for(int i=0;i<m;i++){
        cin>>a[i].first>>a[i].second;
    }
    for(int i=0;i<n;i++){
        int M = INT_MAX,index=0;
        for(int j=0;j<m;j++){
            int x,y;
            x = arr[i].first - a[j].first;
            y = arr[i].second - a[j].second;
            if(M>abs(x)+abs(y)){
                M = abs(x)+abs(y);
                index = j;
            }
        }
        cout<<index+1<<"\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main( void ) {
	int a, b;

	while ( scanf( "%d %d", &a, &b ) != EOF ) {
		int i, min, gcd = 1, lcm = 1, start = 2;

		loop:
		min = ( a > b ? b : a );
		for ( i = start; i <= min / 2; i++ )
			if ( a % i + b % i == 0 ) {
				a /= i;
				b /= i;
				gcd = lcm *= i;
				start = i;
				goto loop;
			}			
		if ( a % min + b % min == 0 ) {
			a /= min;
			b /= min;
			gcd = lcm *= min;
		}
		lcm *= a * b;

		printf( "%d %d\n", gcd, lcm );
	}

	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
int main(void)
{
 int L,R,d,i,t=0;
  scanf("%d%d%d",&L,&R,&d);
  for(i=L;i<=R;i++){
   if(i%d==0)
     t++;
  }
 printf("%d",t);
 return 0;
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define            ll              long long
#define            pb              push_back
#define            mp              make_pair
#define            loop(i,a,n)     for(int i=a;i<n;++i)
#define            clr(x)          memset(x,0,sizeof x)
#define            min3(a,b,c)     min(a,min(b,c))
#define            max3(a,b,c)     max(a,max(b,c))
#define            min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define            max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define            fast            ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define            pii             pair<int,int>
#define            pll             pair<ll,ll>
#define            pli             pair<ll,int>
#define            pil             pair<int,ll>
#define            FF              first
#define            SS              second
#define            PI              acos(-1.0)
#define            bug             cout<<"ok"<<endl;

using namespace std;
using namespace __gnu_pbds;

typedef tree<int , null_type,less<int>,
       rb_tree_tag, tree_order_statistics_node_update> anik;

const int MOD = 1e9 + 7;
const ll MX= 1e9;
const ll INF = 1e9;


ll dp[100009];


main()
{
   int n;
   cin>>n;
   int a[n+9];
   loop(i,0,n)cin>>a[i];
   dp[0]=0;
   dp[1]=abs(a[0]-a[1]);
   loop(i,2,n)
   {
       dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
       //cout<<i<<"->"<<dp[i]<<endl;

   }
   cout<<dp[n-1]<<endl;
}


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

int main() {
	int A, B, K; cin >> A >> B >> K;
	 for( int i = A; i <= B; i++ ){
	 	if( i <= A + K -1 || i >= B - K + 1 )
	 	cout << i << endl;
	 }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, 1, N) {
        cin >> a[i];
        a[i]--;
    }

    vector<int> cnt(N);
    rep(i, 1, N) cnt[a[i]]++;
    vector<int> depth(N, -1);
    
    vv<int> loserDepth(N);

    rep(i, N) {
        if (cnt[i] > 0 || depth[i] != -1) continue;

        depth[i] = 0;
        int n = i;
        while (1) {
            int win = a[n];
            loserDepth[win].push_back(depth[n]);

            if (loserDepth[win].size() == cnt[win]) {
                sort(all(loserDepth[win]));
                int d = 0;
                rep(i, loserDepth[win].size()) {
                    d = max(d + 1, loserDepth[win][i] + 1);
                }
                depth[win] = d;
                n = win;
            }
            else {
                break;
            }
        }
    }

    write(depth[0]);
}

Measured memory_bytes: 6912
MOD = 10 ** 9 + 7
ONE = '1'.freeze

def nCk(n, k)
  return 0 if n < k
  (fact(k + 1, n) * inv(fact(1, n - k) % MOD)) % MOD
end

def fact(s, e)
  (s..e).inject(1) { |r, i| (r * i) % MOD }
end

def inv(x)
  res = 1
  beki = x
  (MOD - 2).to_s(2).reverse.chars do |digest|
    res = (beki * res) % MOD if digest == ONE
    beki = (beki * beki) % MOD
  end
  res
end

def puts_0
  puts 0
  exit
end

x, y = gets.split.map(&:to_i)
count, mod = (x + y).divmod(3)
puts_0 if mod > 0
right_count = x - count
up_count = y - count
puts_0 if right_count < 0 || up_count < 0
puts nCk(count, right_count)


Measured memory_bytes: 1788
N,K=map(int,input().split())
x=list(map(int,input().split()))
minus=[]
plus=[]
for i in range(N):
    if x[i]<0:
        minus.append(abs(x[i]))
    else:
        plus.append(x[i])
minus.append(0)
plus.append(0)

plus.sort()
minus.sort()


ans=int(1e9)
for i in range(K+1):
    if 0<=i<len(plus) and 0<=K-i<len(minus):
        ans=min(ans,plus[i]+minus[K-i]+min(plus[i],minus[K-i]))
print(ans)

Measured memory_bytes: 14252
#include <iostream>

auto main() -> int
{
    int64_t x, k, d;
    std::cin >> x >> k >> d;
    x = std::abs(x);

    int64_t div = x / d;

    if (div > k)
    {
        x = x - (k * d);
    }
    else
    {
        x -= d * div;
        k -= div;

        if ((k % 2) != 0)
        {
            x = std::abs(x - d);
        }
    }

    std::cout << x << std::flush;

    return 0;
}

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

int main() {
    int N; cin >> N;
    vector<vector<int>> F(N, vector<int> (10));
    vector<vector<int>> P(N, vector<int> (11));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> F[i][j];
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 11; j++) {
            cin >> P[i][j];
        }
    }

    ll INF = 1LL << 60;
    ll ans = -INF;
    for (int bit = 0; bit < (1 << 10); bit++) {
        int num = 0;
        for (int i = 0; i < N; i++) {
            if (bit & (1 << i)) num++;
        }
        if (num == 0) continue;
        ll res = 0;
        for (int i = 0; i < N; i++) {
            int cnt = 0;
            for (int j = 0; j < 10; j++) {
                if (bit & (1 << j)) {
                    if (F[i][j] == 1) cnt ++;
                }
            }
            res += P[i][cnt];
        }
        ans = max(ans, res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256