akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("-O2")
#include<bits/stdc++.h>
#define int long long
#define vi vector<int> 
#define pb push_back
#define eb emplace_back
#define For(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define MAX 100005
#define endl '\n'
using namespace std;
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
	#endif
	string s,t;
	cin>>s>>t;
	int n=s.length(),m=t.length(),cnt=0;
	int mn=INT_MAX;
	if(n==m){
		for(int i=0;i<n;i++){
			if(s[i]!=t[i])cnt++;
		}
		cout<<cnt;
		return 0;
	}
	for(int i=0;i<n-m;i++){
		cnt=0;
		for(int j=0;j<m;j++){
			if(s[i+j]!=t[j])cnt++;
		}
		mn=min(cnt,mn);
	}
	cout<<mn;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
    ll h, w, m;    cin >> h >> w >> m;
    map<pair<ll, ll>, ll> g;
    vector<ll> sx(h), sy(w);
    set<ll> gx, gy;
    rep(i, m){
        ll x, y;    cin >> x >> y;  x--, y--;
        g[{x, y}] = 1;
        sx[x]++;    sy[y]++;
    }
    ll mh=0, mw=0;
    rep(i, h) mh = max(mh, sx[i]);
    rep(i, w) mw = max(mw, sy[i]);
    vector<ll> vx, vy;
    rep(i, h) if(mh==sx[i]) vx.push_back(i);
    rep(i, w) if(mw==sy[i]) vy.push_back(i);
    ll res=mh+mw;
    for(auto x: vx){
        for(auto y: vy){
            if(g.count({x, y})) continue;
            cout << res << endl;
            return 0;
        }
    }
    cout << res-1 << endl;
}


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

int main() {
  int K,A,B;
  cin >> K >> A >> B;
  
  for(int i = A; i <= B; i++){
    if(i % K == 0){
      cout << "OK" << endl;
      return 0;
    }
  }
  
  cout << "NG" << endl;
  return 0;
  
}


Measured memory_bytes: 3636
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int p = sc.nextInt();
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			int V = m * (1<<n);
			if(n==0) {
				break;
			}
			int[] t = new int[n];
			for(int i=0;i<n;i++) {
				t[i] = sc.nextInt();
			}
			
			Node[] graph = new Node[V];
			for(int i=0;i<V;i++) {
				graph[i] = new Node();
			}
			for(int i=0;i<p;i++) {
				int x = sc.nextInt()-1;
				int y = sc.nextInt()-1;
				double z = sc.nextInt();
				for(int j=1;j<(1<<n);j++) {
					for(int k=0;k<n;k++) {
						if ((j&(1<<k)) > 0) {
							int to = j^(1<<k);
							graph[x+m*j].to.add(y+m*to);
							graph[x+m*j].cost.add(z/t[k]);
							
							graph[y+m*j].to.add(x+m*to);
							graph[y+m*j].cost.add(z/t[k]);
						}
					}
				}
			}
			
			int s = a+m*((1<<n)-1);
			graph[s].costmin = 0;
			PriorityQueue<Node> q = new PriorityQueue<Node>();
			q.offer(graph[s]);

			while(!q.isEmpty()) {
				Node doneNode = q.poll();

				doneNode.done = true;

				for(int i=0;i<doneNode.cost.size();i++) {
					int to = doneNode.to.get(i);
					double cost = doneNode.costmin + doneNode.cost.get(i);
					if (graph[to].costmin < 0 || cost < graph[to].costmin) {
						graph[to].costmin = cost;
						if(!q.contains(graph[to])) {
							q.offer(graph[to]);
						}
					}
				}
			}

			double ans = Double.POSITIVE_INFINITY;
			for(int i=0;i<(1<<n);i++) {
				double cost = graph[b+m*i].costmin > 0 ? graph[b+m*i].costmin : Double.POSITIVE_INFINITY;
				ans = Math.min(ans, cost);
			}
			if (Double.isInfinite(ans)) {
				System.out.println("Impossible");
			}else{
				System.out.println(ans);
			}
		}
	}

}
class Node implements Comparable<Node>{
	ArrayList<Integer> to = new ArrayList<Integer>();
	ArrayList<Double> cost = new ArrayList<Double>();
	boolean done = false;
	double costmin = -1;

	public int compareTo(Node o) {
		return Double.compare(this.costmin,o.costmin);
	}

}

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

int main()
{	
	long long int n,k,i;
	cin>>n;
	for(i=sqrt(n);i>=1;i--)
	{
		if(n%i==0)
		{
			cout<<i+n/i-2<<endl;
			break;
		}
	}
	
}


Measured memory_bytes: 256
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn string() -> String {
    read()
}

fn int() -> i64 {
    read()
}

fn char() -> char {
    read::<String>().pop().unwrap()
}

fn vecchar() -> Vec<char> {
    string().chars().collect()
}

fn vecint(n: i64) -> Vec<i64> {
    let mut vec = Vec::new();
    for i in 0..n {
        vec.push(int())
    }
    vec
}

fn main() {
    let n = vecchar();
    println!(
        "{}",
        if (n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3]) {
            "Yes"
        } else {
            "No"
        }
    )
}


Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll i,j,k;

ll gcd(ll a,ll b){
    if(b==0){return a;}
    else{return gcd(b,a%b);}
}

int main(){
    ll K;cin>>K;
    ll ans=0;
    for(i=1;i<=K;i++){
        for(j=1;j<=K;j++){
            for(k=1;k<=K;k++){
                ans+=gcd(gcd(i,j),gcd(j,k));
            }
        }
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3676
import java.util.Scanner;

public class Main {
	 static int n[],N[],M;
	 static boolean b;
	
	public static void ri(){
		if(!b){for(int i=0;i<n.length;i++){
			if(i<(n.length/2)){N[i*2]=n[i];}
			else{N[(i-n.length/2)*2+1]=n[i];}
		}b=true;}
		else{{for(int i=0;i<N.length;i++){
			if(i<(N.length/2)){n[i*2]=N[i];}
			else{n[(i-N.length/2)*2+1]=N[i];}
		}}b=false;}
        		
	} 
	
	public static void ka(){
		if(!b){for(int i=0;i<n.length;i++){
			if(i<M){N[i+n.length-M]=n[i];}
			else{N[i-M]=n[i];}
			
		}b=true;
	}
		
		else{for(int i=0;i<N.length;i++){
			if(i<M){n[i+N.length-M]=N[i];}
			else{n[i-M]=N[i];}
			
		}b=false;
	}}

	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		n=new int[sc.nextInt()*2];
		for(int i=0;i<n.length;i++){n[i]=i+1;}
		int m=sc.nextInt();
		N=new int[n.length];
		for(int i=0;i<m;i++){
              M=sc.nextInt();	
              if(M==0){ri();}
              else{ka();}
		}
		if(!b){for(int i=0;i<n.length;i++){
		System.out.println(n[i]);}}
		
		else{for(int i=0;i<n.length;i++){
			System.out.println(N[i]);}}
        
	}

}

Measured memory_bytes: 21564
/* Aizu0002 Digit Number */

#include <stdio.h>

int sum_digits(int n, int base)
{
    int count = 0;

    while(n) {
        count++;
        n /= base;
    }

    return count;
}

int main(void)
{
    int a, b;

    while(~scanf("%d%d", &a, &b))
        printf("%d\n", sum_digits(a + b, 10));

    return 0;
}




Measured memory_bytes: 2696
tmp = gets.chomp.split.map(&:to_i)
a = tmp[0]
b = tmp[1]
answer = []
c= a/b.to_f
d = c.round(8)
# p "c =#{c}"
answer.push(a/b)
answer.push(a%b)
answer.push(sprintf( "%.8f", d ))

puts answer.join(' ')

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





typedef long long ll;
typedef long double ld;


ll a[2][2019];





int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    string s;
    cin>>s;
    ll ans = 0;
    int n = s.size();
    for(int x = 0;x < n;x++){
    	for(int i = 0;i < 2019;i++){
    		a[1][(i*10 + s[x]-'0' + 2019) % 2019] += a[0][i];
		}
		a[1][s[x]-'0']++;
		for(int i = 0;i < 2019;i++){
			a[0][i] = a[1][i];
			a[1][i] = 0;
		}
		ans += a[0][0];
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3744
#include <stdio.h>

int main(void)
{
  int a, b;
  int d, r;
  double f;
  
  scanf("%d %d", &a, &b);
  d = a/b;
  r = a%b;
  f = (double)a/b;
  printf("%d %d %.6f\n", d, r, f);
  
  return 0;
  
}

Measured memory_bytes: 640
N = int(input())
c = list(input())

rcount = 0
wcount = 0
for i in range(N):
    if c[i] == 'W':
        wcount += 1
    else:
        rcount += 1

rst = 0
wst = 0
for i in range(N):
    if i <= rcount-1:
        if c[i] == 'W':
            wst += 1
    else:
        if c[i] == 'R':
            rst += 1
ans = max(wst, rst)
wst -= ans
rst -= ans

ans += wst
ans += rst

print(ans)


Measured memory_bytes: 73344
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)

#include <iostream>
#include <vector>
using namespace std;

//重複順列
vector<ll> buf;
void permutation(ll i, const ll size, const ll range_start, const ll range_end)
{
    if (i == size) {
      // ここで所望の作業を行う
      for(ll itr:buf){
        cout << itr;
      }
    }
    else{
        for(ll j = range_start; j <= range_end; ++j){
            buf[i] = j;
            permutation(i + 1, size, range_start, range_end);
        }
    }
}

int main(void)
{
  ll ans = 0;
  string S;
  cin >> S;
  if(S=="RRR"){
    ans = 3;
  }else if(S=="SRR" || S=="RRS"){
    ans = 2;
  }else if(S=="RSS" || S=="SRS" || S=="SSR" || S=="RSR"){
    ans = 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<cmath>

using namespace std;
int main()
{
    int n;
    double t,ans;
    cin >> n >> t;
    for(int i=0;i<n;i++){
        double a,b;
        cin >> a >> b;
        ans=max(ans,b/a);
    }
    printf("%.10f\n",ans*t);
    return 0;
}



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

int main(){
    ll n;
    cin>>n;
    vector<queue<ll>> l(n,queue<ll>());
    rep(i,n){
        rep(j,n-1){
            int a;
            scanf("%d",&a);
            a--;
            l[i].push(a);
        }
    }
    ll cnt=0;
    ll s=0;
    vector<ll> next;
    rep(i,n)next.push_back(i);
    while(true){
        bool c=true;
        cnt++;
        vector<bool> used(n,false);
        vector<ll> nn;
        for(ll i:next){
            if(l[i].size()){
                ll t=l[i].front();
                if(l[t].size()==0){
                    cout<<-1<<endl;
                    return 0;
                }
                if(l[t].front()==i && !used[i] && !used[t]){
                    used[i]=true;
                    used[t]=true;
                    nn.push_back(i);
                    nn.push_back(t);
                    l[i].pop();
                    l[t].pop();
                    c=false;
                    s++;
                }
            }
        }
        next=nn;
        if(c){
            if(s==n*(n-1)/2){
                cout<<cnt-1<<endl;
                return 0;
            }else{
                cout<<-1<<endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 8960
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
 
struct st {
	double x, y;
} a[105];
int n;
double x, y, ans;
 
bool cmp(st p, st q) {
	return atan2(p.y, p.x) < atan2(q.y, q.x);
}
 
int main() {
	int i, j, c;
	cin >> n;
	for(i=0; i<n; i++) cin >> a[i].x >> a[i].y;
	sort(a, a+n, cmp);
	for(i=0; i<n; i++) {
		x=0.0, y=0.0;
		for(j=i, c=0; c<n; j++, c++) {
			x += a[j%n].x;
			y += a[j%n].y;
			ans = max(ans, sqrt(x*x + y*y));
		}
	}
	printf("%.15f", ans);
	return 0;
}

Measured memory_bytes: 256
s=raw_input()
t=raw_input()
sb=[0]*(len(s)+1)
tb=[0]*(len(t)+1)
for i in xrange(len(s)):
    if s[i]=="B":
        sb[i+1]+=1
for i in xrange(len(s)):
    sb[i+1]+=sb[i]
for i in xrange(len(t)):
    if t[i]=="B":
        tb[i+1]+=1
for i in xrange(len(t)):
    tb[i+1]+=tb[i]
q=int(raw_input())
for i in xrange(q):
    a,b,c,d=map(int,raw_input().split())
    a-=1;c-=1;
    cnt1=b-a;cnt2=d-c
    cnt1+=sb[b]-sb[a]
    cnt2+=tb[d]-tb[c]
    if abs(cnt1-cnt2)%3==0:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 38888
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
 
typedef long long ll;
#define INF 1e9


int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  ll sum = 0;
  REP(i, N){
    cin >> A[i];
    A[i] -= i+1;
    sum += A[i];
  }
  sort(A.begin(), A.end());
  ll ans = 1e15;
  ll B = A[N/2];
  FOR(i, -1, 2){
    B = A[N/2 + i];
    sum = 0;
    REP(j,N){
      sum+= abs(A[j] - (B));
    }
    ans = min(ans, sum);
  }

  FOR(i, -1, 2){
    B = (A[N/2] + A[N/2 -1])/2 + i;
    sum = 0;
    REP(j,N){
      sum+= abs(A[j] - (B));
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h> 
using namespace std; 
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main(void) {
    io;
    string a,b,c;
    cin >> a >> b >> c;
    char x = a.front();
    a = a.substr(1);
    while (true) {
        if (x == 'a') {
            if (a.empty()) {
                cout << 'A' << endl;
                break;
            }
            x = a.front();
            a = a.substr(1);
        } else if (x == 'b') {
            if (b.empty()) {
                cout << 'B' << endl;
                break;
            }
            x = b.front();
            b = b.substr(1);
        } else {
            if (c.empty()) {
                cout << 'C' << endl;
                break;
            }
            x = c.front();
            c = c.substr(1);
        } 
    }
    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
ll A[310][310];
bool habuku[310][310];

int main () {
  cin >> N;
  for (auto i = 0; i < N; ++i) {
    for (auto j = 0; j < N; ++j) {
      cin >> A[i][j];
    }
  }
  fill(&habuku[0][0], &habuku[0][0]+310*310, false);
  for (auto k = 0; k < N; ++k) {
    for (auto i = 0; i < N; ++i) {
      if (i == k) continue;
      for (auto j = i+1; j < N; ++j) {
        if (j == k) continue;
        if (A[i][k] + A[k][j] < A[i][j]) {
          cout << -1 << endl;
          return 0;
        } else if (A[i][k] + A[k][j] == A[i][j]) {
          habuku[i][j] = true;
        }
      }
    }
  }
  ll ans = 0;
  for (auto i = 0; i < N; ++i) {
    for (auto j = i+1; j < N; ++j) {
      if (!habuku[i][j]) ans += A[i][j];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int h = sc.nextInt();
		int w = sc.nextInt();

		String[] c = new String[h];

		for (int i = 0; i < h; i++) {
			c[i] = sc.next();
		}

		for (int i = 0; i < h; i++) {
			System.out.println(c[i]);
			System.out.println(c[i]);
		}
	}
}

Measured memory_bytes: 11468
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(N: int):
    n = N % 10
    if n in (2, 4, 5, 7, 9):
        print("hon")
    elif n in (0, 1, 6, 8):
        print("pon")
    else:
        print("bon")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1<<17;

#define NUM 1000
struct BM{

    int V;
    vector<int> G[NUM];
    int match[NUM];
    bool used[NUM];
     
    void add_edge(int from,int to){
        G[from].push_back(to);
        G[to].push_back(from);
    }
     
    int dfs(int node_id){
        used[node_id] = true;
     
        for(int i = 0; i < G[node_id].size(); i++){
            int adj_node_id = G[node_id][i],pair_id = match[adj_node_id];
            if((pair_id < 0)||(used[pair_id] == false && dfs(pair_id) == true)){
                match[node_id] = adj_node_id;
                match[adj_node_id] = node_id;
                return true;
            }
        }
        return false;
    }
     
     
    int bipartie_matching(){
        int ret = 0;
        for(int i = 0; i < V; i++)match[i] = -1;
        for(int node_id = 0; node_id < V; node_id++){
            if(match[node_id] < 0){
                for(int i = 0; i < V; i++)used[i] = false;
                if(dfs(node_id)){
                    ret++;
                }
            }
        }
        return ret;
    }

};

int main(){
    int m,n;
    while(cin >> m >> n){
        if(m==0&&n==0) break;
        BM bm;
        vector<int> l(m),r(n);
        for(int i=0;i<m;i++) cin >> l[i];
        for(int i=0;i<n;i++){
            cin >> r[i];
            for(int j=2;j*j<=r[i];j++){
                if(r[i]%j==0){
                    for(int k=0;k<m;k++){
                        if(l[k]%j==0||l[k]%(r[i]/j)==0) bm.add_edge(k,m+i);
                    }
                }
            }
            for(int k=0;k<m;k++){
                if(l[k]%r[i]==0) bm.add_edge(k,m+i);
            }
        }
        bm.V=m+n;
        cout << bm.bipartie_matching() << endl;
    }
    return 0;
}



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

int main(){
    int k, t;
    cin >> k >> t;
    vector<int> a(t);
    for (int i = 0; i < t; i++) cin >> a[i];
    int ans = 0;
    for (int i = 0; i < t; i++){
        if (a[i] > k - a[i] + 1) ans = max(ans, 2 * a[i] - k - 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	int a,b;
	cin>>a>>b;
	if(a == 1)
		a += 100;
	if(b == 1) b+= 100;

	if(a<b){
		cout<<"Bob"<<endl;
	}
	else if(a==b){
		cout<<"Draw"<<endl;
	}
	else{
		cout<<"Alice"<<endl;
	}
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


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

#define NDEBUG

// for DEBUG {{{
#ifdef NDEBUG
#define DEBUG_PRINT(fmt, ...) ((void)0)
#else
#define DEBUG_PRINT(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
#endif
#define ASSERT_RANGE(min,x,max) assert(((x)>=(min)) && ((x)<=(max)))
// }}}

#define N_MIN 2
#define N_MAX 50
#define D_MIN 0
#define D_MAX 100

int sort_int(int *a, int N) {// {{{
	int i;
	for (i = 0; i < N-1; i++) {
		int j;
		for (j = i + 1; j < N; j++) {
			if (a[i] > a[j]) {
				int tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	return 0;
}// }}}
void merge_int(int *a, int *b, int lower, int sep, int upper) {// {{{
	int i_lower = lower;
	int i_upper = sep;
	int i_b = 0;
	while ((i_lower < sep) && (i_upper < upper)) {
		if (a[i_lower] < a[i_upper]) {
			b[i_b++] = a[i_lower++];
		} else {
			b[i_b++] = a[i_upper++];
		}
	}
	if (i_lower >= sep) {
		while (i_upper < upper) {
			b[i_b++] = a[i_upper++];
		}
	} else {
		while (i_lower < sep) {
			b[i_b++] = a[i_lower++];
		}
	}
	for (i_lower = 0; i_lower < i_b; i_lower++) {
		a[i_lower+lower] = b[i_lower];
	}
}// }}}
void merge_sort_int(int *a, int *b, int lower, int upper) {// {{{
	int sep;
	if ((lower == upper) || (lower + 1 == upper)) {
		return;
	}
	sep = (lower + upper) / 2;
	merge_sort_int(a,b,lower,sep);
	merge_sort_int(a,b,sep,upper);
	merge_int(a,b,lower,sep,upper);
}// }}}

int main(int argc, char **argv) {
	int N;
	int d[N_MAX];
	int sum = 0;
	int ret = 0;
	fscanf(stdin,"%d",&N);
	ASSERT_RANGE(N_MIN,N,N_MAX);
	{
		int i;
		for (i = 0; i < N; i++) {
			fscanf(stdin,"%d",&d[i]);
			ASSERT_RANGE(D_MIN,d[i],D_MAX);
			sum += d[i];
		}
	}
	{
		int i;
		for (i = 0; i < N; i++) {
			sum -= d[i];
			ret += sum * d[i];
		}
	}
	fprintf(stdout,"%d\n",ret);
	return 0;
}



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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

void solve() {
  int n; cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; ++i) cin >> a.at(i);

  ll ans=0;
  int max=*max_element(a.begin(),a.end());
  int ok=0;
  for(int i=1; i<n; ++i) {
    int x=a.at(i-1), y=a.at(i);
    if(x==max || ok) {
      ans+=(max-x); ok=1;
    } else {
      if(x>=y) {
        ans+=(x-y);
        a.at(i)=x;
      }
    }
  }
  if(a.at(n-1) < max) ans+=(max-a.at(n-1));
  cout << ans << endl;

  return;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


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

int main(){
    int n; cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    set<int> s;
    rep(i,n) s.insert(d[i]);
    cout << s.size() << endl;
}

Measured memory_bytes: 256
import math
N, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
F = sorted([int(i) for i in input().split()])
OK = 10**12
NG = -1

while OK-NG > 1:
    mid = (OK+NG)//2
    cnt = 0
    for a, f in zip(A, F):
        if a*f > mid:
            cnt += math.ceil((a*f-mid)/f)
    if cnt <= K:
        OK = mid
    else:
        NG = mid
print(OK)


Measured memory_bytes: 115828
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
#print(a)
ans = a[0]

if (n-2)%2==0:
  m = (n-2)//2
  for i in range(m):
    ans += 2*a[i+1]
  print(ans)
else:
  m = (n-3)//2
  for j in range(m):
    ans += 2*a[j+1]
  ans += a[m+1]
  print(ans)

Measured memory_bytes: 31604
//20, 05, 2018, 09:03:04 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;

ll INF = ll(1e18);
ll MX = ll(1e8);

int digits(ll n){
    int d = 0;

    while(n){
        d += n % 10LL;
        n /= 10LL;
    }

    return d;
}

map<pair<int, pii>, ll > mp;

int main(){
    ll a, b, c, k;

    cin >> a >> b >> c >> k;
    
    if(k % 2LL == 0LL){
        cout << a - b << endl;
    }else{
        cout << b - a << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int i,j,n,x,a[100001],p,co[100001],sum;
	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
		p=0;
		for(i=1;i<=n;i++)	{	
			scanf("%d",&x);
			if(i%2==1)	{
				if(p==0)	{
					a[p]=1;	co[p]=x;
					p++;
				}
				else {
					if(x==co[p-1])	{
						a[p-1]++;
					}
					else {
						a[p]=1;	co[p]=x;
						p++;
					}
				}
			}
			else {
				if(x==co[p-1])	{
					a[p-1]++;
				}
				else {
					if(p<=1)	{
						a[p-1]++;	co[p-1]=x;
					}
					else {
						a[p-2]+=a[p-1]+1;
						p--;
					}
				}
			}
//			for(j=0;j<p;j++)	printf("%d: a=%d co=%d\n",j,a[j],co[j]);
		}
		sum=0;
		for(i=0;i<p;i++)	{
			if(co[i]==0)	sum+=a[i];
		}
		printf("%d\n",sum);
	}
	return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

int main(){
  int n;cin>>n;
  if(n == 0){
    cout << 0 << endl;
    return 0;
  }
  string ans;
  while(n != 0){
    if(n > 0){
      int a = -(n/2);
      ans = (char)('0'+n-(-2*a)) + ans;
      n = a;    
    }else if (n < 0){
      int a = 0;
      while(true){
        if(n < (-2*a))a++;
        else break;
      }
      ans = (char)('0'+n-(-2*a)) + ans;n = a;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define eps 1e-9
#define nmax 200
#define f(c,a,b) for(int c=a; c<=b; c++)

using namespace std;
typedef double db;
struct P{
    db x, y;
    P(){}
    P(db x, db y) : x(x) , y(y) {}
    P operator - (P a){ return P(x-a.x, y-a.y); }
    db times(P a){ return x*a.y-y*a.x; }
}po[nmax];
typedef P V;
int n;

db area(){
    db ans = 0;
    f(i,3,n) ans += (po[i-1]-po[1]).times(po[i]-po[1]);
    return ans/2;
}

int main(){
    //freopen("owo.in","r",stdin);
    cin >> n;
    f(i,1,n) scanf("%lf%lf", &po[i].x, &po[i].y);
    printf("%.1lf\n", area());
    return 0;
}


Measured memory_bytes: 3244
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

#define MOD 1000000007

int main(int argc, char **argv)
{
    int N, K;
    cin >> N >> K;
    int a[N];
    REP(i, N) cin >> a[i];

    ll dp[N][K + 1];
    REP(i, N) REP(j, K + 1) dp[i][j] = 0;
    REP(i, N) dp[i][0] = 1;
    REP(i, K + 1) {
        if (i <= a[0]) dp[0][i] = 1;
    }

    ll curMax = a[0];
    FOR(i, 1, N) {
        curMax += a[i];
        ll s = dp[i - 1][0];
        int itr = 0;
        FOR(j, 1, K + 1) {
            if (j <= a[i]) {
                s = (s + dp[i - 1][j]) % MOD;
                dp[i][j] = s;
            }
            else if (j <= curMax) {
                ll tmp = (s - dp[i - 1][itr] + dp[i - 1][j]);
                s = (MOD + s - dp[i - 1][itr] + dp[i - 1][j]) % MOD;
                itr++;
                dp[i][j] = s;
            }
        }
    }
    cout << dp[N - 1][K] << endl;

    return 0;
}


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


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

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

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		int p = Integer.parseInt(str[1]);

		str = br.readLine().split(" ");

		int even = 0;
		int odd = 0;
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(str[i]);

			if (a % 2 == 0) {
				even++;
			} else {
				odd++;
			}
		}

		if (p == 0) {
			if (odd == 0) {
				System.out.println((long) Math.pow(2, n));
			} else {
				System.out.println((long) Math.pow(2, n - 1));
			}
		} else {
			if (odd >= 1) {
				System.out.println((long) Math.pow(2, n - 1));
			} else {
				System.out.println("0");
			}
		}
	}
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define vec(j,n) vector<int>(j(n))
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n) cin >> a.at(i);
    ll sum =0;
    for(int i=0;i<n-1;i++){
        if(a.at(i+1) <= a.at(i)){
            sum += (a.at(i) - a.at(i+1));
            a.at(i+1) = a.at(i);
        }

    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4776
i = input()
a,b,c = map(int, i.split())

input = [a, b, c]
k = len(input)
for i in range(k-1, 0, -1):
    for j in range(0, i, 1):
        if input[j] > input[j+1]:
            tmp = input[j]
            input[j] = input[j+1]
            input[j+1] = tmp


print(f"{input[0]} {input[1]} {input[2]}")


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}


int main() {
	int n = ri();
	int m = ri();
	int need = m - m / 2;
	int centre = need * 2 + 1 + m / 2;
	for (int i = 1; i <= m; i++) {
		if (i & 1) printf("%d %d\n", need + 1 + i / 2, need - i / 2);
		else printf("%d %d\n", centre - i / 2, centre + i / 2);
	}
	return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    while(s.size()) {
        s = s.substr(0, s.size() - 2);
        bool ok = true;
        for(int i = 0; i < s.size() / 2; i++) {
            if(s[i] != s[i + s.size() / 2]) {
                ok = false;
                break;
            }
        }
        if(ok) {
            cout << s.size() << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func gcd(m, n int) int {
	if (m % n) == 0 {
		return n
	}
	return gcd(n, m%n)
}


func main() {
	var k int
	fmt.Scan(&k)

	count := 0
	for i:=1; i<=k; i++{
		for j:=1; j<=k; j++{
			for m:=1; m<=k; m++{
				temp := gcd(i, j)
				count += gcd(temp, m)
			}
		}
	}

	fmt.Println(count)

}

Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007
 
typedef long long int ll;
 
const ll INF=(ll)1e18;
 
int main(){
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;;
  
  int dx = tx-sx;
  int dy = ty-sy;

  REP(i,dy)cout << 'U';
  REP(i,dx)cout << 'R';
  REP(i,dy)cout << 'D';
  REP(i,dx)cout << 'L';
  cout << 'L';
  REP(i,dy+1)cout << 'U';
  REP(i,dx+1)cout << 'R';
  cout << "DR";
  REP(i,dy+1)cout << 'D';
  REP(i,dx+1)cout << 'L';
  cout << 'U' << endl;;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{   int k,s,ans=0;
    scanf("%d%d",&k,&s);
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            if(s-i-j<=k&&s-i-j>=0){
                ans++;
            }
        }
    }
    printf("%d",ans);

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int N,M,cap;
main()
{
	while(cin>>N>>M>>cap,N)
	{
		map<string,int>MM;
		vector<pair<pair<int,int>,int> >E;
		string start,goal;
		cin>>start>>goal;
		MM[start]=0;MM[goal]=1;
		int sz=2;
		for(int i=0;i<N;i++)
		{
			string s,t;int dis;cin>>s>>t>>dis;
			int is,it;
			if(MM.find(s)!=MM.end())is=MM[s];
			else is=MM[s]=sz++;
			if(MM.find(t)!=MM.end())it=MM[t];
			else it=MM[t]=sz++;
			E.push_back(make_pair(make_pair(is,it),dis));
		}
		vector<vector<pair<int,int> > >G(sz);
		vector<vector<int> >d(sz,vector<int>(10*cap+1,2e9));
		vector<bool>ok(sz);
		for(int i=0;i<M;i++)
		{
			string s;cin>>s;ok[MM[s]]=true;
		}
		for(pair<pair<int,int>,int>p:E)
		{
			G[p.first.first].push_back(make_pair(p.first.second,p.second));
			G[p.first.second].push_back(make_pair(p.first.first,p.second));
		}
		d[0][cap*10]=0;
		priority_queue<pair<int,pair<int,int> > >P;
		P.push(make_pair(0,make_pair(0,cap*10)));
		while(!P.empty())
		{
			int cost=-P.top().first;
			int u=P.top().second.first;
			int c=P.top().second.second;
			P.pop();
			if(d[u][c]<cost)continue;
			for(pair<int,int>p:G[u])
			{
				int v=p.first;
				if(p.second<=c)
				{
					int now=ok[v]?cap*10:c-p.second;
					if(d[v][now]>cost+p.second)
					{
						d[v][now]=cost+p.second;
						P.push(make_pair(-d[v][now],make_pair(v,now)));
					}
				}
			}
		}
		int ans=2e9;
		for(int i=0;i<=cap*10;i++)ans=min(ans,d[1][i]);
		cout<<(ans<2e9?ans:-1)<<endl;
	}
}



Measured memory_bytes: 51584
#ABC094-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
class WeightedUnionFind:
    def __init__(self, size):
        """
        :param collections.Iterable nodes:
        """
        self._parents = [i for i in range(size)]
        self._ranks = [0 for _ in range(size)]
        self._sizes = [1 for _ in range(size)]
        # 直近の親からの重み。root なら 0
        self._weights = [0 for _ in range(size)]
 
    def unite(self, x, y, w):
        """
        x が属する木と y が属する木を併合
        :param x:
        :param y:
        :param w: x と y の重みの差; (重み y) - (重み x)
        :return:
        """
        rx = self.find(x)
        ry = self.find(y)
        if rx == ry:
            return
 
        # rank が小さい方が下
        if self._ranks[rx] > self._ranks[ry]:
            # x が root
            self._parents[ry] = rx
            self._sizes[rx] += self._sizes[ry]
            # root 間の重みに変換
            self._weights[ry] = w + self._weights[x] - self._weights[y]
        else:
            # y が root
            self._parents[rx] = ry
            self._sizes[ry] += self._sizes[rx]
            # root 間の重みに変換
            self._weights[rx] = -w + self._weights[y] - self._weights[x]
            if self._ranks[rx] == self._ranks[ry]:
                self._ranks[ry] += 1
 
    def find(self, x):
        """
        x が属する木の root
        :param x:
        :return:
        """
        if self._parents[x] == x:
            return x
        root = self.find(self._parents[x])
        self._weights[x] += self._weights[self._parents[x]]
        self._parents[x] = root
        return root
 
    def size(self, x):
        """
        x が属する木のノード数
        :param x:
        :return:
        """
        return self._sizes[self.find(x)]
 
    def weight(self, x):
        """
        :param x:
        :return:
        """
        # 経路圧縮
        self.find(x)
        return self._weights[x]
 
    def diff(self, x, y):
        """
        (y の重み) - (x の重み)
        :param x:
        :param y:
        :return:
        """
        if self.find(x) == self.find(y):
            return self._weights[y] - self._weights[x]
        return float('inf')
n=I()
uf=WeightedUnionFind(n)
for i in range(n-1):
    u,v,w=IL()
    uf.unite(u-1,v-1,w)
C=[0]*n
for i in range(1,n):
    if uf.diff(i,0)%2==0:
        C[i]=0
    else:
        C[i]=1
for i in range(n):
    print(C[i])

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

string sub(long n, int k) {
  vector<int> v;
  for (int i = 0; i < k; ++i) {
    v.push_back(n % 26);
    n /= 26;
  }
  reverse(v.begin(), v.end());
  string r;
  for (int i = 0; i < k; ++i) {
    r += v[i] + 'a';
  }
  return r;
}

int main() {
  long n;
  cin >> n;
  
  int cnt = 0;
  long base = 1;
  for (int i = 0; i < 100; ++i) {
    base *= 26;
    ++cnt;
    if (n <= base) {
      cout << sub(n - 1, cnt) << endl;
      break;
    }
    n -= base;
  }
}

Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<ctype.h>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<utility>
#define For(a,b) for(int i=(a);i<(b);i++)
#define Rep(n) for(int i=0; i<(n); ++i)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
//----------program from here----------

int main(){
    int ans=0,mn=10;
    for(int i=0,T;i<5;++i){
        cin >> T;
        if(T%10){
            mn=min(mn,T%10);
            T=(T/10+1)*10;
        }
        ans += T;
    }
    cout << ans - (10-mn) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)n;i++)

int n,A[50];

bool solve(int i,int j,int m){
    if(j==m) return true; //和jがmになったらok
    if(i>=n) return false; //添字iがn以上になったらだめ
    return solve(i+1,j,m) || solve(i+1,j+A[i],m); //添字を一つ進めてA[i]を入れる場合と入れない場合で考える
}

int main(){
    int q,m;
    cin>>n;
    Rep(i,n) cin>>A[i];
    cin>>q;
    Rep(i,q) {
        cin>>m;
        if(solve(0,0,m)){
            cout<<"yes"<<endl;
        }
        else cout<<"no"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3104
n,t=map(int,input().split())
a=[int(i) for i in input().split()]
mn,mx=10**10,-1
d={}
for i in range(n-1):
    mn=min(a[i],mn)
    mx=max(a[i+1]-mn,mx)
    d[a[i]]=i
d[a[n-1]]=n-1
ans=0
for i in range(1,n):
    if a[i]-mx in d and d[a[i]-mx]<i:
        ans+=1
print(ans)


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;

const ll mod = 1e9+7;

long long Modpow(long long a, int n){
    if(n == 0) return 1;
    if(n%2 == 0){
        long long res = Modpow(a, n/2);
        return res * res % mod;
    }
    return a * Modpow(a, n-1) % mod;
}

int inv(int n) { // 逆元
    return Modpow(n, mod-2);
}

struct Combination { 
    vector<long long> fact, ifact;
    Combination(int n):fact(n+1), ifact(n+1) {
        fact[0] = 1;
        for(long long i = 1; i <= n; i++) fact[i] = fact[i-1]*i % mod;
        ifact[n] = inv(fact[n]);
        for(long long i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i % mod;
    }
    long long operator()(int n, int k) { // modcom (nCk % mod)
        if(k < 0 || k > n) return 0;
        return ((fact[n] * ifact[k]) % mod * ifact[n-k]) % mod;
    }
};



int main(){

    int n;
    cin >> n;

    Combination c(n);

    ll ans = 0;

    for(int cnt = 2; cnt <= n; cnt++) {
        ll tmp = c(n, cnt) * (Modpow(2,cnt) - 2) % mod;
        tmp *= Modpow(8, n-cnt);
        tmp %= mod;
        ans += tmp;
        ans %= mod; 
    }

    cout << ans << endl;
}

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

int main() {
	int n;
	cin>>n;
	unordered_map<string,int>m;
	string a;
	while(n--){
		cin>>a;
		m[a]++;
	}
	cout<<"AC x "<<m["AC"]<<endl;
		cout<<"WA x "<<m["WA"]<<endl;
			cout<<"TLE x "<<m["TLE"]<<endl;
				cout<<"RE x "<<m["RE"]<<endl;


	
	return 0;
}

Measured memory_bytes: 3628
import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.HashMap
import scala.collection.mutable.ArrayBuffer

object Main {

  def move(m:Int, d1:Int, d2:Int) = {
    val x = m/d2 % 10
    m-9*d1-x*d2+9*d2+x*d1
  }
  def end(m:Int) = m == 123456789

  def main(args:Array[String]) = {
    val hist = new ArrayBuffer[Int]
    val phist = new ArrayBuffer[Int]
    val map = new HashMap[Int,Int]
    var pointer = 0
    var found = false
    var count = 0

    val s = { for(i<-1 to 3) yield readLine.split(" ").reduce(_+_) }.reduce(_+_)
    val idx = 8-s.indexWhere(_=='0')
    phist += idx

    val n = s.map{ c => if(c=='0') '9' else c }.toInt
    hist += n
    map += (n->1)

    if(end(n)) found = true
    while(!found) {
      val len = hist.length
      for(i<-pointer until len if !found) {
        val pos = phist(i)
        val data = hist(i)
        val p = Math.pow(10,pos).toInt
        if((8-pos)%3 != 2) {
          val r = move(data, p, p/10)
          if(end(r)) found = true
          else if(!map.contains(r)) {
            hist += r
            map += (r->1)
            phist += pos-1
          }
        }
        if(!found && (8-pos) % 3 != 0) {
          val r = move(data, p, p*10)
          if(end(r)) found = true
          else if(!map.contains(r)) {
            hist += r
            map += (r->1)
            phist += pos+1
          }
        }
        if(!found && (8-pos) / 3 != 0) {
          val r = move(data, p, p*1000)
          if(end(r)) found = true
          else if(!map.contains(r)) {
            hist += r
            map += (r->1)
            phist += pos+3
          }
        }
        if(!found && (8-pos) / 3 != 2) {
          val r = move(data, p, p/1000)
          if(end(r)) found = true
          else if(!map.contains(r)) {
            hist += r
            map += (r->1)
            phist += pos-3
          }
        }
      }
      pointer = (len-pointer)
      count += 1
    }
    println(count)
  }

}

Measured memory_bytes: 122276
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;


int main(){
   int a, b;
   cin >> a >> b;
   out(6-a-b);
}

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

int main(){
	int arr[3][3];
	for (int i = 0;i < 3;i++){
		for (int j = 0;j < 3;j++){
			cin >> arr[i][j];
		}
	}
	for (int i = 0;i < 2;i++){
		for (int j = i + 1;j < 3;j++){
			int sel = arr[0][j] - arr[0][i];
			for (int y = 1;y <= 2;y++){
				if (arr[y][j] - arr[y][i] != sel){
					cout << "No\n";
					return 0;
				}
			}
		}
	}
	cout << "Yes\n";
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
   	
int main() {
	int r, d, x, a;

	cin >> r >> d >> x;
	a = r*x - d;

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

	return 0;
}



Measured memory_bytes: 3604
def next_animal(before, current, claim):
    if (before == current and claim == 'x') or \
        (before != current and claim == 'o'):
        return 'W'
    else:
        return 'S'


def search(S):
    assert len(S) > 2
    init_twos = ['SS', 'SW', 'WS', 'WW']
    ret = ''
    for init_two in init_twos:
        animals = init_two
        for i in range(1, len(S) - 1):
            a = next_animal(animals[i - 1], animals[i], S[i])
            animals += a
        # check: claim of first and last animals
        if animals[1] != next_animal(animals[-1], animals[0], S[0]):
            continue
        if animals[0] != next_animal(animals[-2], animals[-1], S[-1]):
            continue
        ret = animals
        break
    return ret


def main():
    N = int(input())
    S = input()
    ret = search(S)
    if len(ret) > 0:
        print(ret)
    else:
        print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
N, K = map(int, input().split())
S = input()

LR = S.count("LR")

ans = 0

for i in range(N):
    if S[i] == "L":
        if i == 0:
            pass
        else:
            if S[i-1] == "L":
                ans += 1
    else:
        if i == N-1:
            pass
        else:
            if S[i+1] == "R":
                ans += 1


print(min(N-1,ans+2*K))

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

using namespace std;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (; ;) {
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3636
// base: https://atcoder.jp/contests/agc030/submissions/7566849#
// cf. https://ferin-tech.hatenablog.com/entry/2019/01/04/052343

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll powmod(ll x, ll n) { // like pow(x, n)
  ll r = 1;
  while (n) {
    if (n & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return r;
}

ll N, L;

ll solve(const vector<ll>& x) {
  vector<ll> sumx(x);
  for (int i = 1; i < N; i++) {
    sumx[i] += sumx[i - 1];
  }

  ll res = 0;
  for (int i = 0; i < N; ++i) {  // i: starting point of turn.
    int mid = i + (N - i) / 2;  // The last index. e.g. If N = 10 and i = 0, then mid = 5.
    if ((N - i) % 2 == 0) {  // The number of remaining is odd. e.g. 0, 1, ... 9 exist, and i = 0. remaining is 1, 2, ... 9. mid is 5.
      // The result is (X[i]) + (X[i] + revX[N-1]) + (revX[N-1] + X[i+1]) + ... + (X[mid-1] + revX[mid]) = (X[i]*2 + X[i+1]*2 + ... X[mid-1]*2) + ((L-X[mid+1])*2 + (L-X[mid+2])*2 + ... + (L-X[N-1])*2) + (L - X[mid])
      // = (X[i] + X[i+1] + ... + X[mid-1])*2 + (L-X[mid]) + (L-X[mid+1] + L-X[mid+2] + ... + L-X[N-1])*2

      ll val = 2 * (sumx[mid] - sumx[i] - x[mid] + x[i]) - x[mid] - 2 * (sumx[N - 1] - sumx[mid]) + (N - 1 - i) * L;
      res = max(res, val);
    } else {  // The number of remaining is even. e.g. 0, 1, ... 8 exist, and i = 0. remaining is 1, 2, ... 8. mid is 4.
      // (X[i] + X[i+1] + ... + X[mid-1])*2 + X[mid] + (L-X[mid+1] + L-X[mid+2] + ... + L-X[N-1])*2

      ll val = 2 * (sumx[mid] - sumx[i] - x[mid] + x[i]) + x[mid] - 2 * (sumx[N - 1] - sumx[mid]) + (N - 1 - i) * L;
      res = max(res, val);
    }
  }
  return res;
}

int main(int argc, char** argv) {
  cin >> L >> N;
  vector<ll> X(N);
  rep(i, N) {
    cin >> X[i];
  }
  // Try anti-clock order at first.
  ll ans = 0;
  ans = max(ans, solve(X));

  // Calculate reversed.
  reverse(all(X));
  rep(i, N) {
    X[i] = L - X[i];
  }
  ans = max(ans, solve(X));

  cout << ans << endl;
}


Measured memory_bytes: 3428
def search(string,n):
    cnt=0
    for i in range(1000):
        s=str(i)
        if len(s)==1:
            s='00'+s
        elif len(s)==2:
            s='0'+s
        k=0
        for j in range(n):
            if k==2 and s[k]==string[j]:
                cnt+=1
                #print(l[i])
                break
            if s[k]==string[j]:
               k+=1
    
    return cnt
    
    

n=int(input())
s=input()
l=search(s,n)
print(l)


Measured memory_bytes: 41180