akhauriyash/Code-Regression huggingface dataset:
use proconio::{fastout, input};
#[allow(unused_mut)]
#[fastout]
fn main() {
    input! {
        s: String
    }
    let s: Vec<char> = s.chars().collect();
    let rainy = s.iter().filter(|&&c| c == 'R').count();
    let res = match rainy {
        2 => {
            if s[1] == 'S' {
                1
            } else {
                2
            }
        }
        0 => 0,
        1 => 1,
        3 => 3,
        _ => unreachable!(),
    };
    println!("{}", res);
}


Measured memory_bytes: 2144
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

ll k, a, b;

void solve() {
    if (a + 1 < b) {
        ll x = 1;
        while (k > 0) {
            while (x < a) {
                x++;
                k--;
            }
            if (x >= a && k >= 2) {
                k -= 2;
                x -= a, x += b;
            } else if (k == 1) {
                x++;
                k--;
            }
        }
        cout << x << endl;
        return;
    } else {
        cout << 1 + k << endl;
        return;
    }
}

int main() {
    cin >> k >> a >> b;
    solve();
    return 0;
}

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

constexpr int MAX_H = 50;
constexpr int MAX_W = 50;

int H, W;
char grid[MAX_H][MAX_W + 1];

//#define OCTAS
#ifdef OCTAS
constexpr int dh[]{-1, -1, -1, 0, 0, +1, +1, +1};
constexpr int dw[]{-1, 0, +1, -1, +1, -1, 0, +1};
#else
constexpr int dh[]{-1, 0, 0, +1};
constexpr int dw[]{0, -1, +1, 0};
#endif

bool draw(int h, int w) {
  for (int i{}; i < sizeof(dh) / sizeof(int); ++i) {
    int nh = h + dh[i];
    if (nh < 0 || nh >= H)
      continue;
    int nw = w + dw[i];
    if (nw < 0 || nw >= W)
      continue;
    if (grid[nh][nw] == '#') {
      return true;
    }
  }

  return false;
}

int main() {
  scanf("%d%d", &H, &W);
  for (int h{}; h < H; ++h) {
    scanf("%50s", &grid[h]);
  }

  bool judge{true};
  for (int h{}; h < H; ++h) {
    for (int w{}; w < W; ++w) {
      if (grid[h][w] == '.') {
        continue;
      }
      if (!(judge = draw(h, w))) {
        judge = false;
        goto END;
      }
    }
  }
END:
  printf("%s\n", judge ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>            //  IT'S NEVER TOO LATE...
    	using namespace std;
        #include<math.h>
    	#define ll long long
    	#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
        #define forn(i, n) fore(i, 0, n)
        #define fori(i, l, r) fore(i, l, (r) + 1)
        #define sz(v) int((v).size())
        #define all(v) (v).begin(), (v).end()
        #define pb push_back
        #define mp make_pair
        #define ff first
        #define ss second

        const double PI = atan(1)*4;

        int dx[8]={1,0,-1,0,1,-1,-1,1};
        int dy[8]={0,1,0,-1,1,1,-1,-1};

    	
    	vector<int> ar[1000001];
        vector<pair<int,int>> path;
        int vis[1000001],dis[1000001];

        /*void dfs(int node)
        {
            vis[node]=1;

            for(int child : ar[node])
            {
                if(vis[child]==0)
                {
                    dis[child]=dis[node]+1;
                    dfs(child);
                }
            }
        }*/

    /*    void bfs(int i)
        {
            queue<int> q;
            q.push(i);
            vis[i]=1;
            dis[i]=0;

            while(!q.empty())
            {
                int curr=q.front();
                q.pop();

                for(int child : ar[curr])
                    if(vis[child]==0)
                    {
                        q.push(child);
                        dis[child]=dis[curr]+1;
                        vis[child]=1;
                    }
            }
        }*/

        bool isprime(int n)
        {
            for(int i=2;i*i<=n;i++)
                if(n%i==0)
                    return false;
            return true;
        }

        bool comp(pair<int,int> a, pair<int,int> b)
        {
            return b.ff < a.ff ;
        }

        int modpow(int b,int p,int m)
        {
            if(p==0) return 1%m;
            if(p%2) return (b*modpow(b,p-1,m))%m;
            int u=modpow(b,p/2,m);
            return (u*u)%m;
        }

    	int main()  
    	{

    		
    		int t=1;
    		//cin>>t;
    		
    		while(t--)
    		{
                int x,n;
                cin>>x>>n;

                if(n==0)
                {
                    cout<<x;
                    break;
                }
                set<int> s;

                forn(i,n)
                {
                    int x;
                    cin>>x;

                    s.insert(x);
                }

                int i=x,j=x,ans;
                for(;;i++,j--)
                {

                    if(s.count(j) == 0)
                    {
                        ans=j;
                        break;
                    }
                    
                    if(s.count(i) == 0)
                    {
                        ans=i;
                        break;
                    }
                }

                cout<<ans;
            }
            return 0;
    	}

        //              NOW IT'S TIME TO WAKE UP...

Measured memory_bytes: 27068
def main():
    N, x = map(int, input().split())
    a = sorted(list(map(int,input().split())))
    for i in range(N):
        if x - a[i] < 0:
            print(i)
            exit()
        else:
            x -= a[i]
    if x == 0:
        print(N)
    else:
        print(N - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
vector <int> v[100010];
int d1[100010],d2[100010];
int main()
{
	int n,sum1=0,sum2=0;
	cin>>n;
	for(int i=1;i<=n-1;++i)
	{
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}	
	memset(d1,63,sizeof(d1));
	memset(d2,63,sizeof(d2));
	queue <int> q1;
	queue <int> q2;	
	q1.push(1);
	d1[1]=0;
	while(!q1.empty())
	{
		int u=q1.front();
		q1.pop();
		for(int i=0;i<v[u].size();++i)
		{
			if(d1[v[u][i]]>1e8)
			{
				d1[v[u][i]]=d1[u]+1;
				q1.push(v[u][i]);
			}
		}
	}
	q2.push(n);
	d2[n]=0;
	while(!q2.empty())
	{
		int u=q2.front();
		q2.pop();
		for(int i=0;i<v[u].size();++i)
		{
			if(d2[v[u][i]]>1e8)
			{
				d2[v[u][i]]=d2[u]+1;
				q2.push(v[u][i]);
			} 
		}
	}
	for(int i=1;i<=n;++i)
	{
		if(d1[i]<d2[i])
			sum1++;
		if(d1[i]>d2[i])
			sum2++;
		if(d1[i]==d2[i])
			sum1++;
	}
	if(sum1>sum2)
		cout<<"Fennec"<<endl;
	else
		cout<<"Snuke"<<endl;
	return 0;
} 

Measured memory_bytes: 6656
#include <bits/stdc++.h>
//#include <boost/range/algorithm/find_if.hpp>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1000000007;
const int INF = 999999999;

int main(){
    string S, T;
    cin >> S >> T;
    rep(i, S.size()){
        S = S[S.size() - 1] + S.substr(0, S.size()-1);
        //cout << S << endl;
        if(S == T){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
return 0;}
/**
 * g++ code.cpp
 * ./a.out
 * shift + ctrl + i
**/ 


Measured memory_bytes: 256
//
// Created by sark2 on 19-12-2019.
//

#include "bits/stdc++.h"

using namespace std;
#define pb push_back
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define CASES int t;cin>>t;while(t--)

using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;

int main() {
    IOS

    int a, b, c;
    cin>>a>>b>>c;
    if(a+b+c >= 22)cout<<"bust";
    else cout<<"win";

}


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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
std::map<ll, ll> PrimeFactor(ll n){
    std::map<ll, ll> answer;
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            answer[i]++;
            n /= i;
        }
    }
    if(n!=1)answer[n]=1;
    return answer;
}

int maps[1000005]={};
int check(ll n, ll k){
    while((n-1)%k!=0 && n%k==0){
        n = n/k;
    }
    if(n==1){
        maps[k]=1;
        return 1;
    }
    if((n-1)%k==0){
        if(maps[k]==0){
            //cout<<n<<" "<<k<<" "<<"1"<<endl;
            maps[k]=1;return 1;
        }
        else{
            return 0;
        }
    }
    else return 0;
}

int main(){
    maps[1]=1;
    ll n;
    cin>>n;
    if(n==2){
        cout<<"1"<<endl;return 0;
    }
    ll ans=0;
    for(int k=2; k<sqrt(n)+1; k++){
        ans += check(n,k);
    }
    for(int k=1;k<sqrt(n);k++){
        if((n-1)%k==0){
            if((n-1)/k>sqrt(n)){ 
                ans++;
                //cout<<(n-1)/k<<endl;
            }
        }
    }
    ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int ans;
int f[25][25];
int w,h,sx,sy,gx,gy;
void dfs(int x,int y,int turn)
{
	if(turn>10||turn>=ans)return;
	for(int i=y+1;i<w;i++)
	{
		if(x==gx&&i==gy)
		{
			ans=min(ans,turn);
			return;
		}
		if(f[x][i]==1)
		{
			if(i==y+1)break;
			f[x][i]=0;
			dfs(x,i-1,turn+1);
			f[x][i]=1;
			break;
		}
	}
	for(int i=y-1;i>=0;i--)
	{
		if(x==gx&&i==gy)
		{
			ans=min(ans,turn);
			return;
		}
		if(f[x][i]==1)
		{
			if(i==y-1)break;
			f[x][i]=0;
			dfs(x,i+1,turn+1);
			f[x][i]=1;
			break;
		}
	}
	for(int i=x+1;i<h;i++)
	{
		if(gx==i&&gy==y)
		{
			ans=min(ans,turn);
			return;
		}
		if(f[i][y]==1)
		{
			if(i==x+1)break;
			f[i][y]=0;
			dfs(i-1,y,turn+1);
			f[i][y]=1;
			break;
		}
	}
	for(int i=x-1;i>=0;i--)
	{
		if(gx==i&&gy==y)
		{
			ans=min(ans,turn);
			return;
		}
		if(f[i][y]==1)
		{
			if(i==x-1)break;
			f[i][y]=0;
			dfs(i+1,y,turn+1);
			f[i][y]=1;
			break;
		}
	}
	return;
}
int main()
{
	while(1)
	{
		ans=100;
		memset(f,0,sizeof(f));
		scanf("%d %d",&w,&h);
		if(w==0&&h==0)break;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				scanf("%d",&f[i][j]);
				if(f[i][j]==2)
				{
					sx=i;sy=j;
					f[i][j]=0;
				}
				if(f[i][j]==3)
				{
					gx=i;gy=j;
					f[i][j]=0;
				}
			}
		}
		dfs(sx,sy,1);
		if(ans==100)printf("-1\n");
		else printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1040
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
  public static void main(String[] args) {
	FastReader sc = new FastReader();
	int n = sc.nextInt();
	
	if ((n / 10) == 9 || (n % 10) == 9) {
		System.out.println("Yes");
	} else {
		System.out.println("No");
	}
  }
  
  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }
  
    String next() { 
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException  e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() { 
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
        try{
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
      }
  }
}


Measured memory_bytes: 21332
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var s = ReadLine();
			var t = ReadLine();

			if(t.StartsWith(s))
			{
				WriteLine("Yes");
			}
			else
			{
				WriteLine("No");
			}
		}
	}
}


Measured memory_bytes: 18196
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;


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

























class Unionfind {
private:
    vector<int> par;
    vector<int> rank;
    vector<int> counter;
    
public:
    Unionfind(int n) : rank(n), counter(n, 1){
        for(int i = 0; i < n; i++){
            par.push_back(i);
        }
    }
    
    int find(int x){
        if (par[x] == x) {
            return x;
        }
        else {
            return par[x] = find(par[x]);
        }
    }
    
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if (x == y) return;
        
        if (rank[x] < rank[y]) {
            counter[y] += counter[x];
            counter[x] = counter[y];
            par[x] = y;
        }
        else {
            counter[y] += counter[x];
            counter[x] = counter[y];
            par[y] = x;
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
    }
    
    bool same(int x, int y){
        return find(x) == find(y);
    }
    
    ll count(int x){
        return counter[find(x)];
    }
};

int main(){
    ll n, m;
    cin >> n >> m;
    Unionfind uni(n);
    REP(i, m){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        uni.unite(a, b);
    }
    ll ans = 0;
    REP(i, n){
        ans = max(ans, uni.count(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 5884
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.PriorityQueue

case class Data(time: Int, cost: Int, id: Int) extends Comparable[Data] {
  override def compareTo(o: Data): Int = Integer.compare(this.time, o.time)
}


object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)


  val N, Q = in.next().toInt
  private[this] val section = scala.collection.mutable.ArrayBuffer.empty[Data] // (time, cost, id)
  for (i <- 1 to N) {
    val s, t, x = in.next().toInt
    val l = s - x
    val r = t - x
    if (r > 0) {
      section += Data(l, x, i)
      section += Data(r, x, i)
    }
  }
  private[this] val D = new Array[Int](Q)
  for (i <- 1 to Q) {
    D(i-1) = in.next().toInt
  }


  //
  private[this] val hoge: Array[Data] = section.toArray.sorted
  private[this] val fuga = hoge.length
  private[this] var ind = 0

  private[this] val start = new PriorityQueue[(Int, Int)] // (cost, id)
  private[this] val end = new Array[Boolean](N+1)
  for (i <- 0 until Q) {
    breakable {
      while(ind < fuga) {
        val Data(time, x, id) = hoge(ind)

        if(time <= D(i)) {
          if (!end(id)) {
            start.enqueue((-x, id))
            end(id) = true
          }
          else
            end(id) = false
          ind += 1
        }
        else
          break
      }
    }

    var ans = -1
    breakable {
      while(!start.isEmpty) {
        val (cost, id) = start.head
        if (end(id)) {
          ans = -cost
          break
        }
        else
          start.dequeue()
      }
    }
    pw.println(ans)
  }
  pw.flush()
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 137944
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Yulian
 */



#include <iostream>

#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
#include <limits>




#include <ostream>
#include <sstream>


using namespace std;
class C {
public:
	void solve(std::istream& in, std::ostream& out) {
    ios::sync_with_stdio(false);
		long long int n, k, a, b;
		in >> n >> k;
		vector<pair<long long int, long long int>> v(n);
		for(int i = 0; i < n; ++i){
			in >> a >> b;
			v[i] = {a, b};
		}
		sort(v.begin(), v.end());
//		vector<long long int> ps(n);
//		ps[0] = v[0].second;
//		for(int i = 1; i < n; ++i){
//			ps[i] = ps[i-1] + v[i].second;
//		}
//		int l = 0;
//		int r = n-1;
//		int m = (l+r) / 2;
//		while(l < r){
//			if(ps[m] > k){
//				r = m - 1;
//			}else if(ps[m] < k){
//				l = r + 1;
//			}else{
//				out << v[m].first << endl;
//				return;
//			}
//			m = (l+r) / 2;
//		}
//		if(m < n-1 && ps[m+1] < k){
//			out << v[m+1].first << endl;
//			return;
//		}

		long long int sum = 0;
		for(auto it = v.begin(); it != v.end(); ++it){
			sum += it->second;
			if(sum >= k){
				out << it->first << endl;
				return;
			}
		}
	}
};


int main() {
	C solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from random import *
from functools import reduce,partial

def readln():
    return list(map(int,input().split(' ')))

def identity(x):
    """Return the input itself."""
    return x

def constant(c):
    """Return an function which always
    returns the input constant c."""
    def const_function(const,*args):
        return const
    return partial(const_function,c)

def inc(c = 1):
    """Return a function which reads an input x and returns x + c as output.
    By default, c equals 1."""
    return lambda x: x + c

def add(*args):
    """Return the sum of the input."""
    def add2(x,y): return x + y
    return reduce(add2,args)

def mapv(f,*lst):
    """Return a vector of the result of map."""
    return list(map(f,*lst))

def vector(*args):
    """Return a vector of input parameters."""
    return args

def sequence(n,f = constant(0)):
    """Return a vector of length n, and initialize the i'th
    item with f(i).By default the vector will initialized with 0."""
    return [f(i) for i in range(0,n)]

def matrix(n,m,f = constant(0)):
    """Return a 2-dim vector which contains n vectors with length m.
    The j's item of vector i will be initialized by f(i,j).By default,
    the vector will be initialized with 0."""
    return [[f(i,j) for j in range(0,m)] for i in range(0,n)]

def flat(v):
    """Return a flat vector which contains the elements of v in their
    origin order.If the input is not a vector, return a vector which
    only contains the input."""
    if not isinstance(v,list): return [v]
    if not v: return []
    return reduce(add,mapv(flat,v))

def partition(v,f = identity):
    """Partition vector v by f(v[i]).
    e.g. partition([1,2,3,1,2,3],identity()) == {1:[1,1,1], 2:[2,2], 3:[3]}
    By default, the vector will be partitioned by identity function."""
    result = {}
    for item in v:
        key = f(item)
        s = result.get(key)
        if s:
            s.append(item)
        else:
            result.update({key:[item]})
    return result

def getValue(key):
    """Return a function which returns the value of key in a hash-map.
    If the key do not exist, it will throw an error."""
    return lambda x: x[key]

def mapValue(f,m):
    """Replace each value in hash-map m with f(value).
    Return the new hash-map."""
    res = {}
    for key in m:
        res.update({key: f(m[key])})
    return res

n,m = readln()
e = [set() for i in range(n + 1)]
for i in range(m):
    s,t = readln()
    e[s].add(t)
    e[t].add(s)
v = sequence(n + 1,constant(True))
q = sequence(n + 1)
q[0] = 1
p = q[:]
v[1] = False
i = 0
while q[i] > 0:
    s = q[i]
    for t in e[s]:
        if v[t]:
            v[t] = False
            q[i + 1] = t
            break
    i = i + 1
j = 0
while p[j] > 0:
    s = p[j]
    for t in e[s]:
        if v[t]:
            v[t] = False
            p[j + 1] = t
            break
    j = j + 1

print(i + j - 1)
for k in range(1,i):
    print(q[i - k],end = ' ')
for k in range(0,j):
    print(p[k],end = ' ')


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

int main()
{
    long long int N, T;
    long long int sum = 0;
    long long int tsum = 0;
    long long int preb = 0;
    long long int sub = 0;
    cin >> N >> T;
    for(int i = 0; i < N; ++i)
    {
        long long int t;
        cin >> t;
        sub = t - preb;
        if(sub > T)
        {
            sum += tsum+T;
            tsum = 0;
        }
        else
        {
            tsum += sub;
        }

        preb = t;
    }
    
    sum += tsum + T;

    cout << sum << endl;

}

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

int altura[100010],dp[100010];

int solve(int n){
  if(dp[n]!=-1) return dp[n];
  return dp[n]=min(abs(altura[n]-altura[n-1])+solve(n-1),abs(altura[n]-altura[n-2])+solve(n-2));
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(dp,-1,sizeof(dp));
  int n;
  cin>>n;
  for(int i=1;i<=n;i++) cin>>altura[i];
  dp[1]=0;
  dp[2]=abs(altura[2]-altura[1]);
  cout<<solve(n)<<"\n";
  return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <cstdlib>  // abs() for integer
#include <cmath>
#include <bitset>
#include <iomanip>
using namespace std;

int main (){
    int N;
    cin >> N;
    
    vector<int> A(N);
    vector<int> B(N);
    vector<int> 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-1;i++){
        cin >> C[i];
    }
    
    int ans = B[A[0]-1];
    for (int  i=1; i<N;i++){
        ans = ans + B[A[i]-1];
        if (A[i]==A[i-1]+1) ans = ans + C[A[i-1]-1];
    }
    cout << ans;
    }
    
    


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

#define MAX_S 100
#define MAX_N 10

int N, S;

int dfs(int n, int s, int count);

int main(){
	while(1){
		scanf("%d%d", &N, &S);
		if(N == 0 && S == 0) return 0;
		
		printf("%d\n", dfs(0, 0, 0));
	}
}

int dfs(int n, int s, int count){//今nまで足すか否かを決定し、その和がs
	if(count == N) return (s == S)? 1 : 0;
	
	if(n == 10 || s > S) return 0;
	
	return dfs(n + 1, s, count) + dfs(n + 1, s + n, count + 1);
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pi 3.14159265358979323846
#define mod 1000000007
int main()
{ 
    ll p;
    //cin>>p;
    p=1;
    while(p--)
    {
        ll a,b,c,d,e,sum=0,ans=0;
        cin>>a;
        ll A[a];
        for(c=0;c<a;c++) cin>>A[c];
        sum=A[0];
        for(c=1;c<a;c++)
        {
            ans=ans+max((ll)0,sum-A[c]);
            sum=max(sum,A[c]);
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 5140
# 1からn文字目までの部分文字列にACがいくつ含まれるか？

def main():
    N, Q = [int(n) for n in input().split()]
    cnt = [0] * N
    S = input()
    ans = [0] * Q

    cnt[0] = 0
    is_prev_a = S[0] == "A"
    for index in range(1, N):
        char = S[index]
        if char == "A":
            is_prev_a = True
            cnt[index] = cnt[index - 1]
        elif is_prev_a and char == "C":
            is_prev_a = False
            cnt[index] = cnt[index - 1] +  1
        else:
            is_prev_a = False
            cnt[index] = cnt[index - 1]
    for q in range(Q):
        l, r = [int(n) for n in input().split()]
        ans[q] = (cnt[r - 1] - cnt[l - 1])
    
    for i in ans:
        print(i)

if __name__ == "__main__":
    main()

Measured memory_bytes: 55256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    
    class Solve
    {
        const int mod = 1000000007;
        
        
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            
            var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            int N = (int)input[0];
            long K = input[1];

            var A = Console.ReadLine().Split().Select(long.Parse).ToArray();


            
            long mae = 0;
            long ato = 0;
            long ans = 0;

            for(var i = 0; i < N; i++)
            {
                for(var j = 0; j < N; j++)
                {
                    if (i == j) { continue; }
                    if (i > j)
                    {
                        if (A[i] > A[j]) { mae++; }
                    }
                    if (i < j) 
                    {
                        if (A[i] > A[j])
                        {
                            ato++;
                        }
                    }
                }
                
            }


            ans = (K * ato) % mod;
            ans = (ans + (ato + mae) * ((K * (K - 1) / 2) % mod)) % mod;






            Console.WriteLine(ans);
            


            //Console.Out.Flush();

        }

        
    }

    public class Calculation
    {

    }

    public class Graph
    {
        
    }
}



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

#define endl '\n'
#define int long long

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	string s; cin >> s;
	int sum = 0;
	for(char c : s) {
		sum += (c - '0');
		sum %= 9;
	}
	if(!sum) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
#define MOD (10e9+7)
 
using namespace std;
 
 
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); 
    
    string s, t; cin >> s >> t;
    string a(t.begin(), t.end()  - 1);
    if(a == s) cout << "Yes";
    else cout << "No";
    return 0;
}

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

using namespace std;

#define ll long long
#define up(i,j,n)	for(int i=j;i<=n;i++)
#define down(i,j,n)	for(int i=j;i>=n;i--)
#define cmax(a,b)	a=max(a,b)

const int MAXN=1e4+5;

int a[MAXN],f[MAXN],N,ans=0;

namespace solution{
	void Prepare(){
		scanf("%d",&N);
		up(i,1,N)scanf("%d",&a[i]);
	}
	void Solve(){
		f[0]=1;
		up(i,1,N)down(j,10000,a[i])f[j]|=f[j-a[i]];
		up(i,0,10000)if(f[i]&&(i%10!=0))
			cmax(ans,i);
		cout<<ans<<endl;
	}
}

int main(){
	//freopen("input.in","r",stdin);
	using namespace solution;
	Prepare();
	Solve();
	return 0;
}

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


// TEL
int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<int>> pass(N,vector<int>(0));
    int A,B;
    rep(i,M){
        cin >> A >> B;
        pass[A - 1].push_back(B - 1);
        pass[B - 1].push_back(A - 1);
    }

    vector<int> deep(N,-1);
    queue<int> bfs;
    vector<int> root(N,-1);
    bfs.push(0);
    deep[0] = 0;

    int now;
    int nextnow;
    int minnum,memo;
    while(!bfs.empty()){
        now = bfs.front();
        bfs.pop();
        memo = 10000000;
        minnum = 0;
        if(root[now] != -1) continue;
        rep(i,pass[now].size()){
            nextnow = pass[now][i];
            if(deep[nextnow] == -1){
                bfs.push(nextnow);
            }else{
                if(memo > deep[nextnow]){
                    minnum = nextnow;
                    memo = deep[nextnow];
                }
            }
        }
        root[now] = minnum;
        if(memo != 10000000) deep[now] = memo + 1;
        else deep[now] = 0;
    }

    cout << "Yes" << endl;
    rep(i,N - 1){
        cout << root[i + 1] + 1 << endl;;
    }
}

Measured memory_bytes: 10784
#include<bits/stdc++.h>
#define MAX 1000000
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int k;
	cin>>k;
	if(k%2==0||k%5==0)
		cout<<-1<<endl;
	else
	{
		int ans = 0;
		int resto = 0;
		while(1)
		{
			resto *= 10;
			resto += 7;
			resto %= k;
			ans++;
			if(resto==0)
				break;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3696
from collections import defaultdict
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = []
B = []
ans = []
for i in range(N):
    A.append(a[i]^a[(i+1)%N])
    B.append(b[i]^b[(i+1)%N])
if A == B == [A[0]]*N:
    for i in range(N): 
        ans.append((i,a[i]^b[0]))
else:
    A += A    
    d = defaultdict(list)
    for i in range(N):
        d[B[i]].append(i)
    i = 0
    ans = []
    while i < N:
        ok = True
        for j in range(N):
            if B[N-j-1] != A[N-j-1+i]:
                if d[A[N-j-1]] == []:
                    i += N
                    ok = False
                    break
                else:
                    i += N - d[A[N-j-1+i]][-1] - 1
                    ok = False
                    break
        if ok:
            ans.append((i,a[i]^b[0]))
            if len(d[A[N-1+i]]) == 1:
                i += N
            else:
                i += N - d[A[N-1+i]][-2] - 1
for x in ans:
    print(*x)

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

int main(){
    bool judge = true;
    while(true){
    int H,W;
    cin >> H >> W ;
    if ( H == 0 && W == 0) {
        judge = false;
        break;
    }
    else{
        for ( int i = 0 ; i < H ; i++ ){
            for ( int j = 0 ; j < W ; j++ ){
                char ans;
                if ( i == 0 || i == H-1 || j == 0 || j == W-1 ) ans ='#';
                else ans = '.';
                cout << ans;
            } 
            cout << endl;
        }
    cout << endl;
    }
    }
}


Measured memory_bytes: 3008
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <cmath>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9+7;

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n=0;
	string s, mt="CODEFESTIVAL2016";
	cin >> s;
	rep(i,sz(s)) if(s[i]!=mt[i]) n++;
	cout << n <<endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<string>S(N);
  
  for(int i=0; i<N; i++){
    cin >> S.at(i);
  }
  
  int AC =0; int WA =0; int RE =0; int TLE =0;
  for(int i =0; i<N; i++){
    if(S.at(i)=="AC")AC++;
    if(S.at(i)=="WA")WA++;
    if(S.at(i)=="TLE")TLE++;
    if(S.at(i)=="RE")RE++;
  }
  
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
  
  
}

Measured memory_bytes: 6424
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;




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

    int N;
    string s;
    cin >> N;
    unordered_map<string, int> mp;
    for (int i = 0; i < N; i++) {
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] <<endl;
    cout << "TLE x " << mp["TLE"] <<endl;
    cout << "RE x " << mp["RE"] <<endl;
    return 0;
}


Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=2000000;
const ll inf=1e16;
const ll mod=1e9+7;

ll bigmod(ll b, ll p)
{
    ll ans=1;
    for(; p; p>>=1)
    {
        if(p&1) ans=(ans*b)                       %mod;
        b=(b*b)                                   %mod;
    }
    return ans;
}

//int F[MX+5], IF[MX+5];

//ll nCr(ll n, ll r)
//{
//    return (F[n] * IF[r] % mod * IF[n-r]) % mod;
//}

//void FCT()
//{
//    F[0] = IF[0] = 1;
//    for(ll i=1; i<=MX; i++) F[i] = F[i-1] * i % mod;
//    for(ll i=1; i<=MX; i++) IF[i] = Pow(F[i], mod-2);
//}


int main()
{
    //FasterIO;

    int r1, c1, r2, c2;

    cin>>r1>>c1>>r2>>c2;

    const int N=2e6+5;
    vector<int>F(N), IF(N);
    F[0] = IF[0] = 1;
    for(int i=1; i<N; i++)
    {
        F[i] = (ll)F[i-1] * i % mod;
        IF[i] = bigmod(F[i], mod-2);
    }

    auto comb = [&](int n, int k)
	{
		return (ll)F[n] * IF[n-k] % mod * IF[k] % mod;
	};

    int ans=0;
    for(int i=r1; i<=r2; i++)
    {
        ans = (ans + comb(i + c2 + 1, c2)) % mod;
        ans = (ans + mod - comb(i + c1, c1 - 1)) % mod;
    }

    cout<<ans<<"\n";
    return 0;
}


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

int x, y, s;

int tax(int t, int r){
	return (int)((double)t * (100.0 + (double)r) / 100.0);
}

int main(){
	for(;;){
		scanf("%d %d %d", &x, &y, &s);
		if(x == 0 && y == 0 && s == 0) break;
		int max_s = 0;
		for(int t1 = 1; t1 <= s - 1; t1++){
			int s1 = tax(t1, x);
			int s2 = s - s1;
			int t2 = (int)((double)s2 * 100.0 / (100.0 + (double)x));
			if(t2 >= 1 && tax(t2, x) == s2) max_s = max(max_s, tax(t1, y) + tax(t2, y));
			if(t2 + 1 >= 1 && tax(t2 + 1, x) == s2) max_s = max(max_s, tax(t1, y) + tax(t2 + 1, y));
		}
		printf("%d\n", max_s);
	}
	return 0;
}


Measured memory_bytes: 2696
//include
//--------------------------------------------------
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<ctime>

using namespace std;

//conversion
//--------------------------------------------------
inline int toInt(const string &s){
    int v;istringstream sin(s);sin>>v;
    return v;
}
template<class T> inline string toString(T x){
    ostringstream sout;sout<<x;
    return sout.str();
}

//math
//--------------------------------------------------
template<class T> inline T sqr(T x){return x*x;}

//typedef
//--------------------------------------------------
typedef vector<int>VI;
typedef vector<VI>VVI;
typedef vector<string>VS;
typedef pair<int,int>PII;
typedef long long LL;

//container util
//--------------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------------
const int INF=1e9+7;
const int dx[]={0,-1,0,1};
const int dy[]={-1,0,1,0};

//clear memory
#define CLR(a) memset((a),0,sizeof(a))

//debug
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<"(L"<<__LINE__<<")"<<endl

//---------------------------------------------------
struct data{
    int p,n;
    data(int a,int b):p(a),n(b){}
    data(){}
    bool operator<(const data &d)const{
        return p!=d.p?p<d.p:n>d.n;
    }
};

int N,R,L;
int d[1000000];
int t[1000000];
int x[1000000];

int solve(){
    int Point[100000]={0};
    int Total[100000]={0};
    priority_queue<data>Q;
    REP(i,N)Q.push(data(0,i));
    int prev=0;
    REP(i,R+1){
        while(Q.top().p!=Point[Q.top().n])Q.pop();
        if(i==R){
            Total[Q.top().n]+=L-prev;
            break;
        }
        Total[Q.top().n]+=t[i]-prev;
        prev=t[i];
        Point[d[i]]+=x[i];
        Q.push(data(Point[d[i]],d[i]));
    }

    int mav,mac=0;
    REP(i,N){
        if(Total[i]>mac){
            mac=Total[i];
            mav=i;
        }
    }
    return mav+1;
}

int main(){
    cin>>N>>R>>L;
    REP(i,R)cin>>d[i]>>t[i]>>x[i],d[i]--;
    cout<<solve()<<endl;
}

Measured memory_bytes: 22280
#include <bits/stdc++.h>
using namespace std;
char sd[600000]; int n,p[600000],a1[600000],a2[600000],s1=1,ans;
void deal(int a[])
{
	memset(p,0,sizeof p);
	a[1]=1; int j=0; for(int i=2;i<=n;i++)
	{
		while(j&&sd[j+1]!=sd[i]) 
			j=p[j];
		if(sd[j+1]==sd[i]) j++; p[i]=j;
		if(j&&i%(i-j)==0); else a[i]=1;
	}
}
int main()
{
	scanf("%s",sd+1); n=strlen(sd+1); deal(a1);
	for(int i=1,j=n;i<j;i++,j--) swap(sd[i],sd[j]); 
	deal(a2); for(int i=1,j=n;i<j;i++,j--) swap(a2[i],a2[j]);
	for(int i=1;i<=n;i++) s1&=(sd[i]==sd[1]);
	if(s1){ printf("%d\n1\n",n); return 0;}
	if(a1[n]){ printf("1\n1\n"); return 0;}
	for(int i=1;i<n;i++) if(a1[i]&&a2[i+1]) ans++;
	printf("2\n%d\n",ans);
}

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

int a[100010];

int main()
{
    int n; ll L;
    cin >> n >> L;
    rep(i,n) scanf("%d", &a[i]);

    int start = -1;
    rep(i,n-1) {
        if(a[i]+a[i+1] >= L) {
            start = i;
            break;
        }
    }

    if(start == -1) {printf("Impossible\n"); return 0;}

    printf("Possible\n");
    for(int i = 0; i < start; i++) printf("%d\n",i+1);
    for(int i = n-2; i >= start; --i) printf("%d\n",i+1);
    return 0;
}

Measured memory_bytes: 4172
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define rlp(i,a,b) for(int i=a;i>b;i--)
#define ft first
#define sd second
#define pii pair<int,int>
#define all(vect) vect.begin(),vect.end()
#define rall(vect) vect.rbegin(),rend() 
const int num = 200001;
typedef long long ll;
ll dp[num][3];
ll a[num],b[num],c[num];
int main()
{
	int n;
	cin >> n;
	rep(i,1,n+1)
		cin >> a[i] >> b[i] >> c[i];
	dp[1][1]=a[1];
	dp[1][2]=b[1];
	dp[1][3]=c[1];	
	rep(i,2,n+1)
	{
		dp[i][1]=max(dp[i-1][2]+a[i],dp[i-1][3]+a[i]);
		dp[i][2]=max(dp[i-1][1]+b[i],dp[i-1][3]+b[i]);
		dp[i][3]=max(dp[i-1][1]+c[i],dp[i-1][2]+c[i]);
	}
	cout << max(dp[n][1],max(dp[n][2],dp[n][3])) << "\n";


	return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(int i=0;i<((int)(v.size()));++i) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  vi a;
  int cnt1 = 0;
  int cnt0 = 0;
  for(int i=0;i<(n);++i) {
    int tmp; cin >> tmp;
    if(tmp == 0) cnt0++;
    else if(tmp == 1) cnt1++;
    else a.push_back(tmp);
  }
  sort(a.begin(), a.end());
  bool is2andone3 = true;
  int cnt3 = 0;
  int cnt2 = 0;
  for(int i=0;i<((int)(a.size()));++i) {
    cnt3 += a[i] == 3;
    cnt2 += a[i] == 2;
    is2andone3 &= a[i] == 2 || a[i] == 3;
  }
  is2andone3 &= cnt2 > 0 && cnt3 == 1;
  if(is2andone3) {
    swap(a[(int)(a.size())-2], a[(int)(a.size())-1]);
  }
  if(cnt0 + cnt1 == n) {
    if(cnt0 % 2 == 0) {
      for(int i=0;i<(cnt0);++i) cout << 0 << endl;
      for(int i=0;i<(cnt1);++i) cout << 1 << endl;
    } else if(cnt1 > 0) {
      for(int i=0;i<(cnt0-1);++i) cout << 0 << endl;
      cout << 1 << endl;
      cout << 0 << endl;
      for(int i=0;i<(cnt1-1);++i) cout << 1 << endl;
    } else {
      for(int i=0;i<(cnt0);++i) cout << 0 << endl;
    }
  } else if(cnt0 > 0) {
    if(cnt1 > 0) {
      if(cnt0 % 2 == 0) {
        for(int i=0;i<((int)(a.size()));++i) cout << a[i] << endl;
        for(int i=0;i<(cnt0);++i) cout << 0 << endl;
        for(int i=0;i<(cnt1);++i) cout << 1 << endl;
      } else {
        for(int i=0;i<((int)(a.size()));++i) cout << a[i] << endl;
        for(int i=0;i<(cnt0-1);++i) cout << 0 << endl;
        cout << 1 << endl;
        cout << 0 << endl;
        for(int i=0;i<(cnt1-1);++i) cout << 1 << endl;
      }
    } else {
      if(cnt0 % 2 == 0) {
        for(int i=(0);i<((int)(a.size()));++i) cout << a[i] << endl;
        for(int i=0;i<(cnt0);++i) cout << 0 << endl;
      } else {
        if(is2andone3 && (int)(a.size()) == 2) {
          swap(a[(int)(a.size())-2], a[(int)(a.size())-1]);
        }
        for(int i=(1);i<((int)(a.size()));++i) cout << a[i] << endl;
        for(int i=0;i<(cnt0-1);++i) cout << 0 << endl;
        cout << a[0] << endl;
        cout << 0 << endl;
      }
    }
  } else {
    for(int i=0;i<((int)(a.size()));++i) cout << a[i] << endl;
    for(int i=0;i<(cnt1);++i) cout << 1 << endl;
  }
}



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

class Program
{
    void Run()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        for (int i = 0; i < n; i++)
        {
            int a = sc.NextInt();
            if (a % 2 != 0) continue;
            if (a % 3 != 0 && a % 5 != 0)
            {
                Console.WriteLine("DENIED");
                return;
            }
        }
        Console.WriteLine("APPROVED");
    }

    static void Main(string[] args)
    {
        new Program().Run();
    }

    static long Gcd(long a, long b)

    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }

    static long Lcm(long a, long b)
    {
        long d = Gcd(a, b);
        return a / d * b;
    }

    static long RepeatedSquare(long n, long p, long m)
    {
        if (p == 0) return 1;
        if (p % 2 != 0) return n * RepeatedSquare(n, p - 1, m);
        long t = RepeatedSquare(n, p / 2, m);
        return (t * t) % m;
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 13140
N, M, X = map(int, input().split())
A = [0]*M
#for i in range(M):
A = list(map(int, input().split()))

count = 0
for i in range(M):
    if A[i] < X:
        count += 1
    else:
        break

if count * 2 > M:
    print(M-count)
else:
    print(count)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  int n; cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  sort(a.begin(), a.end(),[](ll x, ll y) {
			    return x > y;
			  });
  ll res = 0;
  rep1(i,n-1) {
    res += a[i/2];
  }
  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 4788
import java.util.*;

public class Main {

	public static Scanner sc = new Scanner(System.in);
	public static int N, M;
	
	public static void main(String[] args) {
		
		while (true) {
			N = sc.nextInt();
			M = sc.nextInt();
			if (N == 0 && M == 0)
				break;
			
			ArrayList<Edge> es = new ArrayList<Edge>();
			for (int i = 0; i < N; i++) {
				es.add(new Edge(sc.nextInt(), sc.nextInt()));
			}
			
			Collections.sort(es);
			int ans = 0;
			for (int i = 0; i < N; i++) {
				int D = es.get(i).D, P = es.get(i).P;
				if (M == 0) {
					ans += D * P;
				} else if (D <= M) {
					M -= D;
				} else {
					
					ans += P * (D - M);
					M = 0;
				}
				
			}
			System.out.println(ans);
		}
	}
}

class Edge implements Comparable<Edge> {
	int D, P;
	Edge(int D, int P) {
		
		this.D = D;
		this.P = P;
	}
	
	public int compareTo(Edge e) {
		return  e.P - this.P;
	}
}

Measured memory_bytes: 14000
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int n;
  cin >>n;
  long long int a[n];
  for(int i=0;i<n;i++)cin >> a[i];
  long long int tate=0,yoko=0;
  sort(a,a+n);
  reverse(a,a+n);
  for(int i=0;i<n;i++){
    if(a[i]==a[i+1]){
      if(tate==0)tate=a[i];
      else if(yoko==0)yoko=a[i];
      i++;
    }
  }
  cout <<  tate*yoko <<endl;     
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
	int n, m, ans = 1;
	cin >> n >> m;
	for(int i = m / n; i >= 1; i--){
		if((m - n * i) % i == 0){
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

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


int main(){
    double a, b, x; cin >> a >> b >> x;
    int mark = (int)a*a*b;
    double ans;
    if(x * 2 == mark){
        ans = radToDeg(atan(b/a));
    }
    else if(x*2 > mark){
        ans = radToDeg(atan((mark-x) * (2.0/(a*a*a))));
    }
    else ans = radToDeg(atan((a*b*b) /(2.0 * x)));

    cout << fixed;
    cout << setprecision(10);
    cout << ans << endl;

}

Measured memory_bytes: 256
#!/usr/bin/env python3

import fractions

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

N = int(input())
T = [int(input()) for _ in range(N)]

g = T[0]
for i in range(1,N):
    g = lcm(g, T[i])
print(g)


Measured memory_bytes: 5048