akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    int c_0=0,c_1=0,c_2=0,c_3=0;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        if(s=="AC")
            ++c_0;
        else if(s=="WA")
            ++c_1;
        else if(s=="TLE")
            ++c_2;
        else if(s=="RE")
            ++c_3;
    }
    cout<<"AC x "<<c_0<<endl;
    cout<<"WA x "<<c_1<<endl;
    cout<<"TLE x "<<c_2<<endl;
    cout<<"RE x "<<c_3<<endl;
    return 0;
}


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

bool check(string s){
    string s1=s;
    reverse(s.begin(),s.end());
    if(s1==s) return true;
    return false;
}

int main(){

        string s;
        cin>>s;
        int n=s.size();
        if(!check(s)){
            cout<<"No"<<endl;
            return 0;
        }
        string s1="";
        for(int i=0;i<(n-1)/2;i++){
            s1+=s[i];
        }
        string s2="";
        for(int i=(n+1)/2;i<n;i++){
            s2+=s[i];
        }
        if(check(s1) && check(s2)) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;

}


Measured memory_bytes: 256
import java.util.*;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] s = new int[M];
        String[] c = new String[M];

        if(M==0){
            int a;
            if(N==1){
                a = 0;
            }
            else if(N==2){
                a = 10;
            }
            else{
                a = 100;
            }
            System.out.println(a);
            return;
        }
        for(int i=0; i<M; i++){
            s[i] = sc.nextInt();
            c[i] = sc.next();
        }
        int x, y;
        if(N==1){
            x = 0;
            y = 9;
        }
        else if(N==2){
            x = 10;
            y = 99;
        }
        else{
            x = 100;
            y = 999;
        }
        loop:for(int i=x; i<=y; i++){
            String st = String.valueOf(i);
            for(int j=0; j<M; j++){
                if(st.charAt(s[j]-1)!=c[j].charAt(0)){
                    break;
                }
                if(j==M-1){
                    System.out.println(st);
                    break loop;
                }
            }
            if(i==y){
                System.out.println(-1);
            }
        }
    }
}

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

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

    char mat[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mat[i][j];
        }
    }

    int ans[h][w];
    for(int i = 0; i < h; i++){
        int cloud = -1;
        for(int j = 0; j < w; j++){
            if(cloud != -1) cloud++;
            if(mat[i][j] == 'c')    cloud = 0;
            ans[i][j] = cloud;
        }
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << ans[i][j] << " \n"[j == w-1];
        }
    }
    
    return 0;
}


Measured memory_bytes: 3104
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

#define PLIMIT 123456*2
int prime[PLIMIT+10];
int cum[PLIMIT+10];//閉区間
void makep(ll n){prime[0]=prime[1]=1;for(int i=2;i*i<=n;i++)if(!prime[i])for(int j=i*i;j<=n;j+=i)prime[j]=1;}

int main(){
	makep(PLIMIT);
	rep(i,1,PLIMIT+1)cum[i]=cum[i-1]+!prime[i];
	ll n;
	while(scanf("%lld",&n),n){
		printf("%lld\n",cum[2*n]-cum[n]);
	}
}


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

pair<int, int> a[222222];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		scanf("%d%d", &a[i].second, &a[i].first);
	sort(a, a + n);
	long s = 0;
	for (int i = 0; i < n; i++) {
		s += a[i].second;
		if (s > a[i].first) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 1920
import sys,math,collections,itertools
input = sys.stdin.readline

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

Q = [0]*(N)
for i in range(N):
    Q[P[i]-1]=i

cnt = 1
ans = 1
for i in range(N-1):
    if Q[i+1]>Q[i]:
        cnt += 1
    else:
        ans = max(ans,cnt)
        cnt = 1
ans = max(ans,cnt)
print(N-ans)


Measured memory_bytes: 25112
# verify-helper: PROBLEM https://judge.yosupo.jp/problem/scc
import sys

input = sys.stdin.buffer.readline
sys.setrecursionlimit(6 * 10 ** 5)


class StronglyConnectedComponets:
    def __init__(self, n: int) -> None:
        self.n = n
        self.edges = [[] for _ in range(n)]
        self.rev_edeges = [[] for _ in range(n)]
        self.vs = []
        self.order = [0] * n
        self.used = [False] * n

    def add_edge(self, from_v: int, to_v: int) -> None:
        self.edges[from_v].append(to_v)
        self.rev_edeges[to_v].append(from_v)

    def dfs(self, v: int) -> None:
        self.used[v] = True
        for child in self.edges[v]:
            if not self.used[child]:
                self.dfs(child)
        self.vs.append(v)

    def rdfs(self, v: int, k: int) -> None:
        self.used[v] = True
        self.order[v] = k
        for child in self.rev_edeges[v]:
            if not self.used[child]:
                self.rdfs(child, k)

    def run(self) -> int:
        self.used = [False] * self.n
        self.vs.clear()
        for v in range(self.n):
            if not self.used[v]:
                self.dfs(v)
        self.used = [False] * self.n
        k = 0
        for v in reversed(self.vs):
            if not self.used[v]:
                self.rdfs(v, k)
                k += 1
        return k


def main() -> None:
    N, M = map(int, input().split())
    scc = StronglyConnectedComponets(N)
    for _ in range(M):
        u, v = map(int, input().split())
        scc.add_edge(u, v)
    scc.run()
    ans_size = max(scc.order) + 1
    ans = [[] for _ in range(ans_size)]
    for i, c in enumerate(scc.order):
        ans[c].append(i)
    print(ans_size)
    for row in ans:
        print(len(row), *row)


if __name__ == "__main__":
    main()


Measured memory_bytes: 235372
#include <cstdio>
#include <algorithm>

int main() {
  int n;
  scanf("%d", &n);
  int dp[3];
  for (int i = 0; i < 3; ++i) scanf("%d", &dp[i]);
  for (int i = 1; i < n; ++i) {
    int t[3];
    for (int j = 0; j < 3; ++j) {
      scanf("%d", &t[j]);
      int mx = 0;
      for (int k = 0; k < 3; ++k) {
        if (k != j) mx = std::max(mx, dp[k]);
      }
      t[j] += mx;
    }
    for (int j = 0; j < 3; ++j) dp[j] = t[j];
  }
  printf("%d\n", std::max(dp[0], std::max(dp[1], dp[2])));
  return 0;
}


Measured memory_bytes: 128
def main():
    n, *b = map(int, open(0).read().split())

    m = []
    for k in range(1, n+1):
        for i in range(n - k, -1, -1):
            if b[i] == i + 1:
                b.pop(i)
                m.append(i+1)
                break

    if len(b) > 0:
        print(-1)
    else:
        print('\n'.join(map(str, m[::-1])))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int n,a,v;
	pii d[25]={};
	cin>>n;
	rer(i,1,n) d[i].se=i;
	rep(i,0,n){
		cin>>a>>v;
		d[a].fi=v;
	}
	sort(d+1,d+n+1);
	rer(i,1,n){
		if(d[i].fi==d[n].fi){
			o(d[i].se<<" "<<d[i].fi); break;
		}
	}
}

Measured memory_bytes: 1164
K, N = map(int, input().split())
A = list(map(int, input().split()))
max_dis = 0
max_i = 0
for i in range(N):
    if i==0:
        max_dis = A[0] + (K - A[-1])
        max_i = 0
    else:
        dis = A[i]-A[i-1]
        if max_dis < dis:
            max_dis = dis
            max_i = i
if max_i == 0:
    move_dis = A[-1] - A[0]
    print(move_dis)
else:
    move_dis = (K-A[max_i]) + A[max_i-1]
    print(move_dis)

Measured memory_bytes: 92312
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] q = new int[(int)Math.pow(10 , 5) + 2];
		Arrays.fill(q , 0);
		int a;
		for(int i = 0 ; i < n ; i++){
			a = Integer.parseInt(sc.next());
			q[a]++;
			q[a + 1]++;
			q[a + 2]++;
		}
		Arrays.sort(q);
		ou.println(q[(int)Math.pow(10 , 5) + 1]);
		ou.flush();
	}
}

Measured memory_bytes: 60508
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int n,m,q;  
vector<vector<int>>Q;
int ans = 0;
vector<int>A;

void dfs(int ptr = 0, int before = 1){
    if(ptr == n){
        int tmp = 0;
        rep(i, q){
            int a = A[Q[i][0]];
            int b = A[Q[i][1]];
            if(b-a == Q[i][2])  tmp += Q[i][3];
        }
        ans = max(ans, tmp);
    }else{
        for(int i = before; i <= m; i++){
            A[ptr] = i;
            dfs(ptr+1, i);
        }
    }
}

int main(){
    cin >> n >> m >> q;
    A.resize(n);
    A[0] = 1;
    Q.resize(q);
    rep(i, q)   Q[i].resize(4);
    rep(i, q){
        int a,b,c,d;    cin >> a >> b >> c >> d;
        a--;    b--;
        Q[i][0] = a;
        Q[i][1] = b;
        Q[i][2] = c;
        Q[i][3] = d;
    }
    dfs();
    cout << ans << endl;
}


Measured memory_bytes: 3596
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Messaging;
using System.Security.Principal;
using System.Text;
class Simple {
    private int N;
    void Solve() {
        //input
        N = io.Int;
        //cal
        var sum = 0;
        var lastNum = 0;
        for(int i = 1; sum < N; ++i) {
            sum += i;
            lastNum = i;
        }    
        var over = sum - N;
        //ret
        for(int i = 1; i <= lastNum; ++i) {
            if(i != over) {
                Console.WriteLine(i);
            }                
        }         
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    void Stream() {
        Solve();
        io.writeFlush();
    }
}
class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] {' '};
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if(BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while(st == "") st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int p[50];
  int cnt=0;
  rep(i,n){
    cin>>p[i];
    if(p[i]!=i+1)cnt++;
  }
  if(cnt<=2) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int a, b;
    cin >> a >> b ;
    
    if(a == 1){
        a = 14;
    }
    
    if(b == 1){
        b = 14;
    }
    
    //*
    if(a < b){
        cout << "Bob" << endl;
    } else if(a > b){
        cout << "Alice" << endl;
    } else {
        cout << "Draw" << endl;
    }
    //*/
    
    //cout << max(a * b, c * d) << endl;

    return 0; 
}


Measured memory_bytes: 3600
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		for(int i=1;i<=x;i++){
			int num=i;
			if(num%3==0){
				System.out.print(" "+i);
			}else{
				while(true){
					if(num%10==3){
						System.out.print(" "+i);
						break;
					}
					num=num/10;
					if(num<3)
						break;
				}
			}
		}
		System.out.println();
	}
}


Measured memory_bytes: 28696
while True:
    n = int(input())
    if n==0:
        break
    m = 0
    while True:
        if n==1:
            break
        if n % 2==0:
            n = n / 2
            m += 1
        else:
            n = n * 3 + 1
            m += 1
    print(m)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S; cin >> S;
  if( (int) S.size() == 1){ cout << "-1 -1" << endl; return 0;}
  for(int i = 0; i < (int) S.size() - 1; i++){
    if( S[i] == S[i+1]){ cout << i+1 << " " << i+2 << endl;//1-index化
                        return 0;}
    if( S[i] == S[i+2] && i+2 < (int)S.size()){ 
                         cout << i+1 << " " << i+3 << endl;
                        return 0;}
  }
  cout << "-1 -1" << endl; return 0;}

Measured memory_bytes: 512
import java.util.*;

public class Main {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();
        int a = sc.nextInt();

        if (x<a){
            System.out.println("0");
        }else if (a<=x){
            System.out.println("10");
        }



        }
    }



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

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  for(int i=0;i<N;i++){
    cin >> D.at(i);
  }
  int tmp;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(D.at(i) > D.at(j)){
        tmp = D.at(i);
        D.at(i) = D.at(j);
        D.at(j) = tmp;
      }
    }
  }
  int Max = 1;
  for(int i=0;i<N-1;i++){
    if(D.at(i) < D.at(i+1)){
      Max++;
    }
  }
  cout << Max << endl;
}

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

typedef long double elm;

const elm inf = 1e100;
const int M = 256;
int N;
vector<int> I;
int cnt[M];

elm test(int s, int a, int c) {
  fill(cnt, cnt+M, 0);
  int r = s;
  for(int i = 0; i < N; ++i) {
    r = (a*r+c) % M;
    int o = (I[i] + r) % M;
    ++cnt[o];
  }
  elm res = 0;
  for(int i = 0; i < M; ++i) {
    if(cnt[i]) {
      res += cnt[i] * (log(cnt[i]) - log(N));
    }
  }
  return -res;
}

int main() {
  while(cin >> N && N) {
    I.resize(N);
    for(int i = 0; i < N; ++i) {
      long long s;
      cin >> s;
      I[i] = s % M;
    }
    elm mini = inf;
    int S, A, C;
    for(int s = 0; s <= 15; ++s) {
      for(int a = 0; a <= 15; ++a) {
	for(int c = 0; c <= 15; ++c) {
	  elm h = test(s,a,c);
	  if(h < mini) {
	    mini = h;
	    S = s;
	    A = a;
	    C = c;
	  }
	}
      }
    }
    cout << S << " " << A << " " << C << endl;
  }
  return 0;
}

Measured memory_bytes: 1264
#include<iostream>
#include<math.h>
using namespace std;
bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; 

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
            return false;
    }
    return true;
}
int main() {
  int n;
  int sum[1000000];
  sum[0]=0;
  sum[1]=0;
  sum[2]=1;
  for(int i=3;i<1000000;i++) {
    sum[i]=sum[i-1];
    if(IsPrime(i)) 
      sum[i]++;
 }
  while(cin>>n)
    cout<<sum[n]<<endl;
  return 0;
}



Measured memory_bytes: 6904
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    auto ss = aryread!string();
    ss.map!(s => s[0]).writeln();
}


Measured memory_bytes: 380
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>

auto& in = std::cin;
auto& out = std::cout;

int32_t N;
int64_t POW, BACE;
int32_t h[100000];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N>> POW>>BACE;
	for (int32_t i = 0; i < N; ++i)
	{
		in >> h[i];
	}
	std::sort(h, h + N);
	
	using BS_INT = int64_t;
	BS_INT beg = -1, end = 1000000000 + 1;
	while (beg + 1 != end) {
		BS_INT mid = (beg + end) / 2;

		//ここに書く
		int64_t need = 0;
		int64_t bace = BACE*mid;
		int64_t add = POW-BACE;
		for (auto iter = std::upper_bound(h,h+N,bace); iter != h+N; ++iter)
		{
			need += (*iter- bace + add - 1) / add;
		}

		if (need <= mid) {
			end = mid;
		}
		else {
			beg = mid;
		}
	}
	out << end << endl;

	return 0;
}
#endif




Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

int main()
{
  int n;
  int64_t ans=0;
  cin>>n;
  vector<int> t(n);
  for(int i=0;i<n;i++)
  {
    cin>>t.at(i);
  }
  for(int i=1;i<n;i++)
  {
    if(t.at(i-1)>t.at(i))
    {
      ans+=t.at(i-1)-t.at(i);
      t.at(i)=t.at(i-1);
    }
  }
  cout<<ans<<endl;
}

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

int main(){
    int h, n;
    cin >> h >> n;
    int a[n];
    int sigma = 0;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        sigma += a[i];
    } 
    if (sigma >= h) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>
#include <iomanip>

using namespace std;
using lint = long long;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<int>;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
using pqi = priority_queue<int>;
using pql = priority_queue<lint>;
#define mii = map<int, int>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define repf(i, f, n) for (int i = (f); i < (n); i++)
#define mp(x, y) make_pair((x), (y))
#define pb(x) push_back((x))
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define space (char)0x20
#define yes "Yes"
#define no "No"

constexpr lint MOD = 1e9 + 7;
int A, B, C, D, E, F, G, H, I, J, K, L, M, N;
int O, P, Q, R, S, T, U, V, W, X, Y, Z;
// string s;
// int ans = 1;
int sum = 0;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> N;

	rep1(i, N) {
		rep1(j, N) {
			rep1(k, N) {
				sum += gcd(i, gcd(j, k));
			}
		}
	}
    
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3616
from math import cos, radians

a, b, h, m = map(int, input().split())
d0 = m * 6
d1 = (h * 60+m) * 0.5
ans = a ** 2 + b ** 2 - 2 * a * b * cos(radians(abs(d1 - d0)))
ans **= 0.5
print(ans)


Measured memory_bytes: 9372
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vecll>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
#define MM " "
#define INF INT_MAX
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}


    
void go();
int n;


int f(ll x,ll y){
    int ma=-1;
    rep(i,32){
        if((x%3)==1 and (y%3)==1)chmax(ma,(int)i);
        x/=3;y/=3;
    }
    if(ma==-1)return 0;
    ll res=1;
    rep(i,ma)res*=3;
    return res;
}
vec to_3(ll x){
    vec res;
    rep(i,32){
        res.pb(x%3);x/=3;
    }
    // reverse(all(res));
    return res;
}

main(){
    ios
    int q=in();
    while(q--){
        ll a=lin()-1,b=lin()-1,c=lin()-1,d=lin()-1;
        if(abs(a-c) > abs(b-d)){
            swap(a,b);swap(c,d);
        }
        vec A=to_3(a),B=to_3(b),C=to_3(c),D=to_3(d);
        int t=-1;
        vec s={-1};
        rep(i,32)if(A[i] == 1 and C[i]==1)s.pb(i);
        while(1){
            t=s.back();s.pop_back();
            if(t==-1){
                cout<<abs(a-c)+abs(b-d)<<endl;break;
            }
            if(b > d){
                swap(b,d);vec t=B;B=C;C=t;
            }
            bool f=0;
            ll T=1;
            rep(i,t){
                T*=3;
            }
            if(b/T == d/T)f=1;
            if(b/T + 1 == d/T and (b/T%3)==2 and (d/T%3)==0)f=1;
            if(f) {continue;}
            ll ans=0;
            if(a>c)swap(a,c);
            ll L=(a/T)*T-1, R=(a/T)*T+T;
            ans=abs(a-L)+abs(c-L)+abs(b-d);
            chmin(ans,abs(R-a)+abs(R-c)+abs(b-d));
            cout<<ans<<endl;
            break;
        }
    }
}




Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数list 1 <= x <= n
auto divv = [](ll n) {
  unordered_set<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.insert(i);
      if(i*i != n) v.insert(n/i);
    }
  }
//   sort(ALL(v));
  return v;
};

auto isprime = [](auto n){
  bool isPrime = true;
  for(decltype(n) i = 2; i <= sqrt(n); ++i)
  {
      if(n % i == 0)
      {
          isPrime = false;
          break;
      }
  }
  return isPrime;
};

int main() {
    ll n,k;
    cin>>n>>k;


    unordered_set<ll> divn,divk;
    divn = divv(n);
    divk = divv(k);
    ll sum=0;
    for(auto it:divk) if(divn.count(it)) if(isprime(it)) sum++;
    pr(sum);
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>

using namespace std;

int main() {
    unsigned long long n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    unsigned long long a1 = 0, a2 = 0;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (a[i] > a[j]) ++a1;
            if (a[i] < a[j]) ++a2;
        }
    }
    unsigned long long answer = a1 * (k + 1) + a2 * (k - 1);
    if (answer % 2 == 0) {
        answer /= 2;
    } else {
        k /= 2;
    }
    answer %= 1000000007;
    cout << (answer * k) % 1000000007 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define s second
#define f first
long long const mod = pow(2,32);
#define inf 1000000000000000
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod)+mod)%mod;}
inline ll mul(ll a, ll b){ return (((a%mod)*(b%mod))%mod+mod)%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

ll power(ll x,ll y,ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m;
    return (y%2 == 0)? p : (x * p) % m;
}

ll modInv(ll x)
{
    return power(x,mod-2,mod)%mod;
}


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

    ll n;
    cin>>n;
    ll a[n];
    map<ll,ll>mp;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }

    ll z=0;
    for(auto x:mp)
    {
        z=z+(x.second*(x.second-1))/2;
    }
    map<ll,ll>ans;
    for(auto x:mp)
    {
        ll y=(x.second*(x.second-1))/2;
        ll k=x.second-1;
        ll y2=(k*(k-1))/2;
        ans[x.first]=z-y+y2;
    }
    for(int i=0;i<n;i++)
        cout<<ans[a[i]]<<endl;
    
    return 0;
}


Measured memory_bytes: 18944
main = do
  s <- getLine
  t <- getLine
  let ans = compute s t
  putStrLn ans

compute :: String -> String -> String
compute s t
  | null rs = "UNRESTORABLE"
  | True = last rs
  where
    rs =
      [ map ena (s1 ++ t ++ drop (length t) s2)
      | (s1,s2) <- map (flip splitAt s) [0..length s - length t]
      , match t s2
      ]

match "" _ = True
match (_:ts) ('?':ss) = match ts ss
match (t:ts) (s:ss) = t == s && match ts ss

ena '?' = 'a'
ena c = c


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int N, D, X, ans = 0;
    cin >> N >> D >> X;
    rep(i, N) {
        int A;
        cin >> A;
        for (int a=0;; ++a) {
            int tmp = a*A + 1;
            if (tmp > D) break;
            ans++;
        }
    }
    cout << ans+X << endl;
    return 0;
}


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

int main(){
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a+2), t(b+2);

    s[0] = -1e15;
    s[a+1] = 1e15;
    t[0] = -1e15;
    t[b+1] = 1e15;

    for(int i=1; i<=a; i++) cin >> s[i];
    for(int i=1; i<=b; i++) cin >> t[i];

    for(int i=0; i<q; i++){
        ll x;
        cin >> x;

        auto S = upper_bound(s.begin(), s.end(), x);
        auto T = upper_bound(t.begin(), t.end(), x);

        ll sr = *S - x, sl = *(S-1) - x;
        ll tr = *T - x, tl = *(T-1) - x;

        ll ans = min({abs(sl) + abs(tl - sl), abs(tl) + abs(tl - sl), abs(sr) + abs(sr - tr), abs(tr) + abs(sr - tr), abs(2*sl) + abs(tr), abs(2*sr) + abs(tl), abs(2*tl) + abs(sr), abs(2*tr) + abs(sl)});

        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
N,K = map(int,input().split())
A = list(map(int,input().split()))
INF = 10**9+7

cnt = [0]*N

for i in range(N):
    c = 0
    x = A[i]
    for j in range(i+1,N):
        y = A[j]
        if x > y:
            c += 1
    cnt[i] = c*K
for i in range(N):
    x = A[i]
    c = 0
    for j in range(N):
        y = A[j]
        if x > y:
            c += 1
    cnt[i] += (c*K*(K-1)//2)%INF
print(sum(cnt)%INF)

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

int main(){

    // 1. 入力情報.
    int X;
    scanf("%d", &X);
    
    // 2. 級を計算.
    int ans = 8 - (X - 400) / 200;
    
    // 3. 出力.
    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 3812
#coding: utf-8

def check(a):
    result = 0
    for o in a:
        while True:
            if o % 2 == 0:
                o = o / 2
                result += 1
            else:
                break
    
    return result


if __name__ == "__main__":
    n = int(input())
    tmp = input().split(" ")
    a = []
    for i in range(n):
        a.append(int(tmp[i]))
    
    print(check(a))

Measured memory_bytes: 4148
#include<bits/stdc++.h>
using namespace std;
const int N=200005,mod=998244353;
char s[N];
int f[N][3][3];
int power(int x,int y)
{
	int s=1;
	for(;y;y/=2,x=1ll*x*x%mod)
		if(y&1) 
			s=1ll*s*x%mod;
	return s;
}
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	if(n==2)
	{
		printf("%d\n",1+(s[1]!=s[2]));
		return 0;
	}
	if(n==3)
	{
		if(s[1]==s[2]&&s[2]==s[3]) 
			puts("1");
		else if(s[1]==s[2]||s[2]==s[3]) 
			puts("6");
		else if(s[1]==s[3]) 
			puts("7");
		else 
			puts("3");
		return 0;
	}
	int fl=1;
	for(int i=1;i<n;i++)
		if(s[i]!=s[i+1]) 
			fl=0;
	if(fl)
	{
		puts("1");
		return 0;
	}
	int ans=power(3,n-1);
	int v=0;
	for(int i=1;i<=n;i++)
		v=(v+s[i]-'a')%3;
	for(int i=0;i<3;i++)
		f[1][i][i]=1;
	for(int i=2;i<=n;i++)
		for(int j=0;j<3;j++)
			for(int k=0;k<3;k++)
				for(int l=0;l<3;l++)
					if(k!=l)
						f[i][(j+l)%3][l]=(f[i][(j+l)%3][l]+f[i-1][j][k])%mod;
	for(int i=0;i<3;i++)
		ans=(ans+mod-f[n][v][i])%mod;
	fl=1;
	for(int i=1;i<n;i++)
		if(s[i]==s[i+1]) 
			fl=0;
	printf("%d\n",(ans+fl)%mod);
	return 0;
}

Measured memory_bytes: 7424
using System;

namespace CADDi_2018_D___Harlequin
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var isSecond = true;
            for (int i = 0; i < N; i++) if (int.Parse(Console.ReadLine()) % 2 == 1) isSecond = false;
            Console.WriteLine(isSecond? "second":"first");
        }
    }
}


Measured memory_bytes: 17232
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;


public class Main{

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		scan.nextLine();

		//List<Integer> list = new ArrayList<Integer>(N);
		//int arr[][] = new int[N][N];
		Map<Integer,Integer> hmap = new HashMap<>();

		int hi = 0;

		for (int i=1; i<=N; i++) {
			hmap.put(scan.nextInt(),i);

		}


		int cnt = 0;

		for(int j=1; j<=N; j++) {

			cnt = hmap.get(j);
			String ans = String.valueOf(cnt);

			StringBuilder sb = new StringBuilder(ans);
			sb.append(" ");
			System.out.print(sb);

		}

	}
}



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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll)1e9 + 7;
constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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 Edge {
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    string s;
    cin >> s;
    if(s == "RRR")
        cout << 3 << en;
    else if(s == "RRS" or s == "SRR")
        cout << 2 << en;
    else if(s == "SSS")
        cout << 0 << en;
    else
        cout << 1 << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>

int n,S[100000];

int search(int T);

int main(void)
{
  int q,T;
  int i, count = 0;

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

  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%d",&T);
    
    if(search(T) == 1){
      count++;
    }
  }
  printf("%d\n",count);

  return 0;
}




int search(int T){
  int r;
  int l = 0;
  int m = 0;

  r = n;

  while(l < r){
    m = (r+l)/2;
    if(T > S[m]){
      l = m+1;
    } else if(T < S[m]){
      r = m;
    } else {
      return 1;
    }
  }
    
  return 0;
}



Measured memory_bytes: 2172
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

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

  int N, K;
  cin >> N >> K;
  vector<int> P(N);
  for (auto &x: P) cin >> x;

  /*
  0 1 2 3 7 5 4 6 8 9
  0 1 2 3
    1 2 3 7
      2 3 5 7
        3 4 5 7
          4 5 6 7
            4 5 6 8
              4 6 8 9
  */

  vector<int> partialVector;
  set<int> partialSet;
  for (int i = 0; i < K; i++) {
    partialVector.push_back(P[i]);
    partialSet.insert(P[i]);
  }
  sort(partialVector.begin(), partialVector.end());
  bool sorted = true;
  for (int i = 0; i < K; i++) {
    if (partialVector[i] != P[i]) {
      sorted = false;
      break;
    }
  }
  int decBase = 0;
  for (int i = 0; i < K-1; i++) {
    if (P[i] > P[i+1]) {
      decBase = i + 1;
    }
  }
  int ans = 0;
  if (!sorted) ans++;
  for (int i = K; i < N; i++) {
    decBase = max(0, decBase-1);
    if (P[i-1] > P[i]) {
      decBase = K - 1;
    }
    bool front = false, back = false;
    if (*(partialSet.begin()) == P[i-K]) front = true;
    partialSet.erase(P[i-K]);
    partialSet.insert(P[i]);
    if (*(partialSet.rbegin()) == P[i]) back = true;
    if (decBase > 0){
      if (front && back) ;
      else ans++;
    }
    else {
      if (back) sorted = true;
      else ans++;
    }
    cerr << decBase << " " << ans << endl;
  }
  if (sorted) ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11252
import math
 
A, B = list(map(int, input().split()))
 
rangeA = [A / 0.08, (A + 1) / 0.08]
rangeB = [B / 0.1, (B + 1) / 0.1]
 
if rangeA[0] < rangeB[0]:
  if math.ceil(rangeB[0]) < rangeA[1]:
    print(math.ceil(rangeB[0]))
    exit(0)
elif rangeA[0] > rangeB[0]:
  if math.ceil(rangeA[0]) < rangeB[1]:
    print(math.ceil(rangeA[0]))
    exit(0)
else:  # rangeA[0] == rangeB[0]
  if math.ceil(rangeA[0]) < rangeB[1] and math.ceil(rangeA[0]) < rangeA[1]: 
    print(math.ceil(rangeA[0]))
    exit(0)
print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
// ifstream fin("filename.in");
// ofstream fout("filename.out");

int main(){
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	int i,j;
	for(i=0;i<n;i++)
		cin>>a[i];
	k--;
	int q = a[0];
	j = 1;
	for(i=k+1;i<n;i++)
	{
		if(a[i]>q)
			cout<<"Yes\n";
		else
			cout<<"No\n";
		q = a[j];
		j++;
	}
}


Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,w,h,x,y,s,t;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            cin>>w>>h;
            std::vector<vector<int>> vec(h+1,vector<int>(w+1));
            for (int i=0;i<n;i++) {
                cin>>x>>y;
                vec.at(y).at(x)=1;
            }
            /*
            for (int mm=0;mm<h+1;mm++) {
                for (int hh=0;hh<w+1;hh++) {
                    cout<<vec.at(mm).at(hh);
                }
                cout<<endl;
            }*/
            cin>>s>>t;
            int max=0;
            for (int j=1;j+t<=h+1;j++) {
                for (int k=1;k+s<=w+1;k++) {
                    int count=0;
                    for (int hoge=j;hoge<j+t;hoge++) {
                        for (int piyo=k;piyo<k+s;piyo++) {
                            if (vec.at(hoge).at(piyo)==1) {
                                //cout<<hoge<<" "<<piyo<<endl;
                                count++;
                            }
                        }
                    }
                    //cout<<endl;
                    if (count>max) {
                        max=count;
                    }
                }
            }
            cout<<max<<endl;
        }
    }
}



Measured memory_bytes: 3208
A = []

for _ in range(3):
  for e in list(map(int, input().split())):
    A.append(e)

N = int(input())

for _ in range(N):
  n = int(input())
  if n in A:
    A[A.index(n)] = 0

patterns = [
  [0, 1, 2],
  [3, 4, 5],
  [6, 7, 8],
  [0, 3, 6],
  [1, 4, 7],
  [2, 5, 8],
  [0, 4, 8],
  [2, 4, 6]
]

for pattern in patterns:
  if not any([A[e] for e in pattern]):
    print('Yes')
    exit()

print('No')

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
	int n,i;
	int tmp;
	long min = 1000000;
	long max = -1000000;
	long sum=0;

	scanf("%d",&n);

	for(i=0; i<n; i++){
		scanf("%d", &tmp);
		if(tmp <= min)
			min = tmp;
		if(tmp >= max)
			max = tmp;
		sum += tmp;
	}
	printf("%ld %ld %ld\n", min,max,sum);

	return 0;
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};




template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}


vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.pb(buffer);
    }
    return v;
}




int main(){

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

    ll a, b, c, k;
    cin >> a >> b >> c >> k;


    if(k%2 == 0){
        ppp(a-b);
    }
    else{
        ppp(b-a);
    }



    return 0;
}


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

using namespace std;


typedef long long int lli;

int main()
{
    lli N, W;
    cin >> N >> W;
    W += 1;
    vector<lli> w(N), v(N);
    for (int i = 0; i < N; ++i)
        cin >> w[i] >> v[i];

    vector<vector<lli>> dp(N, vector<lli>(W, 0));

    for (int i = w[0]; i < W; ++i)
        dp[0][i] = v[0];

    for (int i = 1; i < N; ++i)
        for (int j = 0; j <= W; ++j)
        {
            dp[i][j] = max(dp[i][j], dp[i-1][j]);
            if (j - w[i] >= 0)
                dp[i][j] = max(dp[i][j], dp[i-1][j - w[i]] + v[i]);
        }

    cout << dp[N-1][W-1];

    return 0;
}

Measured memory_bytes: 82348
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define fix(n) cout<<fixed<<setprecision(n);
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int n; cin>>n;
  vector<int> a(n);
  rep(i,0,n) cin>>a[i];
  reverse(all(a));
  rep(i,0,n){
    cout<<a[i];
    if(i!=n-1) cout<<" ";
  }
  co("");
  return 0;
}


Measured memory_bytes: 3100
N = int(input())
mod = 10**9+7

if N==1:
    print(0)
elif N ==2:
    print(2)
else:
    ans2 = 0
    ans1 = 2
    ans0 = 8
    
    for i in range(N-1):
        ans2 = ans2*10 + ans1*1
        ans1 = ans1*9 + ans0*2
        ans0 = ans0*8
        ans2 %= mod
        ans1 %= mod
        ans0 %= mod
        
    print(ans2)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
#include <iomanip>

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

cout << fixed << setprecision(15);
int64_t N, K; cin >> N >> K;

double P = 0.;
rep(i, 1, N+1){
    double Pi = 1. / N;
    int64_t num = i;
    while (num < K){
        num *= 2;
        Pi *= .5;
    }
    P += Pi;
}

cout << P << endl;

}
// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(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();}

int main(){
    std::ios::sync_with_stdio(false);
    int k;
    cin >> k;
    vector<ll> a(k);
    for(int i=0;i<k;++i)
    {
        cin >> a[i];
    }

    ll maxi = 2;
    ll mini = 2;
    for(int i=k-1;i>=0;--i)
    {
        ll max_mul = maxi / a[i] * a[i];
        if(max_mul < mini || maxi < max_mul)
        {
            maxi = -1;
            break;
        }

        maxi = max_mul + a[i] - 1;
        mini = mini % a[i] == 0 ? mini : (mini / a[i] + 1) * a[i];
    }
    
    if(maxi == -1)
    {
        cout << maxi << endl;
    }
    else
    {
        cout << mini << " " << maxi << endl;
    }



}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in) ;
		String strings1 = sc.next();
		String strings2 = sc.next();
		String strings3 = sc.next();
		sc.close();
		
		//入力値を配列に入れて、配列[0]の要素をとりたい
		
		//要素の中身が小文字の場合、大文字に変える
		System.out.print(strings1.charAt(0));
		System.out.print(strings2.charAt(0));
		System.out.print(strings3.charAt(0));
		
		
	}
}


Measured memory_bytes: 21844