akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <utility>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cstdlib>
#define FOR(i,m,n) for(int i = (m); i < (n); i++)
#define REP(i,n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vint;

int main() {
	int a, b, result{};
	scanf("%d%d", &a, &b);
	if(a > b) {
		result += a;
		a--;
	} else {
		result += b;
		b--;
	}
	if(a > b) {
		result += a;
		a--;
	} else {
		result += b;
		b--;
	}
	printf("%d\n", result);
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

//Reverse string reverse
func Reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
			runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func search(s string) bool {
	rs := Reverse(s)
	words := []string{"dream", "dreamer", "erase", "eraser"}

	for i, j := 0, len(words)-1; i < j; i, j = i+1, j-1 {
		words[i], words[j] = words[j], words[i]
	}

	for _, v := range words {
		rv := Reverse(v)
		rs = strings.Replace(rs, rv, "", -1)
	}

	return len(rs) == 0
}

func main() {
	var s string
	
	fmt.Scan(&s)

	if search(s) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

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

    using namespace std;

    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define FOR(i,a,b) for(int i = (a); i < (b); i++)
    #define rep(i,n) FOR(i,0,n)
    #define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
    #define SZ(a) (int)a.size()
    #define ALL(a) a.begin(),a.end()
    #define PB push_back

    typedef long long LL;

    const double PI = acos(-1.0);
    const int INF = 1000 * 1000 * 1000 + 7;
    const LL LINF = INF * (LL)INF;
    const int MAS =4e5; //5;
    const int MOD = 1e9 + 7;
    const double EPS = 1e-8;

int n;
 int mul (int a ,int b)
{
  return  a *1ll * b %MOD ;
}

  struct  M{

      vector<vector<int>>t ;
      M()
      {
          t.resize(n,vector<int > (n)) ;
      }
      M operator * (const M& b)const {
          M c = M();
          rep(i,n)
          {
              rep(j,n)
              {
                  rep(k,n)
                  {
                      c.t[i][k]+=mul(t[i][j], b.t[j][k]) ;
                      c.t[i][k]%=MOD;
                  }
              }
          }
          return c;

      }

  };
    int main() {
        IOS
        //   freopen("series.in","r",stdin);
        //   freopen("series.out","w",stdout);
        LL k;
        cin >> n >> k ;
        vector<vector<int>> can(n  ,vector<int > (n ));
        rep(i, n) {
            rep(j, n) {
                cin >> can[i][j];
            }
        }
        M answer = M() ;
        rep(i,n)
        {
            answer.t[i][i] = 1;
        }

       M m = M();
        m.t = can;
        while (k){
            if(k%2)
            {
                answer =answer*m  ;
            }
            m = m * m ;
            k/=2;
        }
        LL total = 0;
        rep(i,n)
        {
            rep(j,n)
            {
                total+=answer.t[i][j] ;
                //cout << total << endl;
            }
        }
        cout << total %MOD << endl;


    }

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n;
  cin >> n;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  sort(v.begin(), v.end());
  ll a = 0, b = 0;
  rep(i, n) {
    if (i%2 == 0) {
      a += v.at(n-1-i);
    } else {
      b += v.at(n-1-i);
    }
  }
  cout << a-b << endl;
}

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

int main()
{
	int A, B, C, X;
	cin >> A >> B >> C >> X; X /= 50;
	int res = 0;
	for (int i = 0; i <= A; i++) {
		for (int j = 0; j <= B; j++) {
			for (int k = 0; k <= C; k++) {
				res += (i * 10 + j * 2 + k == X);
			}
		}
	}
	cout << res << endl;
	return 0;
}


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

namespace AtCoder.AtCoder_Begginer_Contest_167
{
    class B
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            int C = int.Parse(input[2]);
            int K = int.Parse(input[3]);

            int sum = CalcSum(A, B, C, K);

            Console.WriteLine(sum);
            // Console.ReadKey();
        }

        private static int CalcSum(int A, int B, int C, int K)
        {
            int k = K;
            int sum = 0;
            if (k <= A)
            {
                sum += k * 1;
                return sum;
            }
            else
            {
                sum += A;
                k = k - A;
            }

            if (k <= B)
            {
                sum += k * 0;
                return sum;
            }
            else
            {
                sum += B * 0;
                k = k - B;
            }

            if (k <= C)
            {
                sum += k * -1;
                return sum;
            }
            else
            {
                sum += C * -1;
                k = k - C;
            }

            return sum;
        }
    }
}


Measured memory_bytes: 27548
n, k = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)

counts = as.each.with_object(Array.new(n + 1, 0)) do |a, h|
  h[a] += 1
end.sort!

ans = 0
while counts.size > k
  ans += counts.shift
end

puts ans


Measured memory_bytes: 18416
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a+b>=10){
            System.out.println("error");
        }else{
            System.out.println(a+b);
        }
        sc.close();
    }

}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
int dp[3010][3010];

signed main(){
	int n, t; cin >> n >> t;
	vector<P> data(n);
	for(int i = 0; i < n; i++) cin >> data[i].first >> data[i].second;
	sort(data.begin(), data.end());
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= t - 1; j++){
			dp[i + 1][j] = dp[i][j];
			if(j - data[i].first >= 0) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - data[i].first] + data[i].second);
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i++) ans = max(ans, dp[i][t - 1] + data[i].second);
	cout << ans << endl;
}

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

int min( long int a, long int b )
{
    if( a < b )
        return a;
    else
        return b;
}

int main()
{
    int n, m, k;
    string str, s[100];
    map<string,int> a;
    
    while( cin >> n )
    {
        if( n == 0 )
            break;

        for( int i = 0; i < n; i++ )
        {
            cin >> str >> m;
            a[str] = m;
        }

        cin >> m;

        for( int i = 0; i < m; i++ )
        {
            cin >> str >> k;
            long int sum = 0;
            for( int j = 0; j < k; j++ )
            {
                cin >> s[j];
                sum += a[s[j]];
            }
            a[str] = min( a[str], sum );
        }

        cin >> str;

        cout << a[str] << endl;
    }
    
    return 0;
}



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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int main(){
  /*ll N,M;cin >> N >> M;
  vector<tuple<ll,ll,ll>> edges;
  for(int i = 0;i < M;i++){
    int a,b,c;cin >> a >> b >> c;
    a--;b--;
    c = -c;
    edges.emplace_back(a,b,c);
  }
  bool upd = true;
  vector<ll> d(N,INF);
  d[0] = 0;
  ll step = 0;
  vector<bool> NEG(N,0);
  while(upd){
    upd = false;
    for(int i = 0;i < M;i++){
      ll a,b,c;
      tie(a,b,c) = edges[i];
      if(NEG[a]){
        NEG[b] = 1;
      }
      ll newD = d[a] + c;
      if(d[b] > newD){
        upd = true;
        d[b] = newD;
        NEG[b] = 1;
      }
    }
    step++;
    if(step > N * 2){
      cout << "inf" << endl;
      return 0;
    }
  }
  cout << -d[N-1] << endl;*/
  ll N;cin >> N;
  vector<ll> A(N);
  vector<ll> B(1,1);
  for(int i = 0;i < N;i++)cin >> A[i];
  for(int i = 0;i < N-1;i++){
    if(A[i] == A[i+1])B.back()++;
    else B.push_back(1);
  }
  ll ans = 0;
  for(int i = 0;i < B.size();i++){
    ans += B[i] / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Numerics;
 
   class Program
    {
        static void Main()
        {
            var MOD = (BigInteger)1e9 + 7;
            var N = int.Parse(Console.ReadLine());
 
            var ans = BigInteger.ModPow(10, N, MOD);
            ans += BigInteger.ModPow(8, N, MOD);
            var bc = (BigInteger.ModPow(9, N, MOD)*2)%MOD;
            ans = ans - bc + MOD;
            Console.WriteLine(ans%MOD);
        }
    }

Measured memory_bytes: 27728
import java.io.BufferedReader
import java.util.*
import kotlin.collections.ArrayDeque
import kotlin.math.max

fun main() = abc128d()

@OptIn(ExperimentalStdlibApi::class)
fun abc128d() = SimpleFastIOWithToken_abc128d().exec {
    val (n, k) = readInt() to readInt()
    val values = List(n) { readLong() }

    var answer = 0L

    for (pollL in 0..k) for (pollR in 0..(k - pollL)) for (push in 0..(k - pollL - pollR)) {
        val deque = ArrayDeque(values)
        val taken = PriorityQueue<Long>()

        repeat(pollL) { taken.add(deque.removeFirstOrNull() ?: return@repeat) }
        repeat(pollR) { taken.add(deque.removeLastOrNull() ?: return@repeat) }
        repeat(push) { if (taken.isNotEmpty() && taken.first() < 0) taken.remove() }

        answer = max(answer, taken.sum())
    }

    println(answer)
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_abc128d(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readLong(): Long = java.lang.Long.valueOf(readString())

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }

    fun exec(action: SimpleFastIOWithToken_abc128d.() -> Unit) {
        var t: Throwable? = null
        Thread(null, { action() }, "solve", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, t1 -> t = t1 } }
            .apply { start() }.join()
        t?.let { throw it }
        kotlin.io.print(sb)
    }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 62820
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
ll longinf=1ll<<60;
int inf=1<<29;
//mleしなければぜんぶllでかく。


int main(){
	int n;
	cin>>n;
	int c[n];
	rep0(i,n) cin>>c[i];
	vector<int> a;
	a.push_back(c[0]);
	rep1(i,n-1){
		if(c[i-1]!=c[i]) a.push_back(c[i]);
	}
	int m=a.size();
	ll dp[m+1];
	int itr[200002];
	rep0(i,200002) itr[i]=-1;
	dp[0]=1;
	rep1(i,m)dp[i]=0;
	int acm[m+1];
	rep0(i,m+1) acm[i]=0;
	ll mod=1e9+7;
	rep1(i,m){
		dp[i]=dp[i-1];
		if(itr[a[i-1]]>=0){
		dp[i]=(dp[i]+acm[itr[a[i-1]]])%mod;
		acm[i]=(acm[itr[a[i-1]]]+dp[i-1])%mod;
		}
		else{
			acm[i]=dp[i-1];
		}
		//cout<<dp[i]<<" "<<acm[itr[a[i-1]]-1]<<" "<<itr[a[i-1]]<<endl;
		itr[a[i-1]]=i;
	}
	cout<<dp[m]<<endl;
    return 0;
}

Measured memory_bytes: 5108
N = int(input())
An = list(map(int,input().split()))
An.append(0)
dis = abs(An[0])
for i in range(N):
    dis += abs(An[i] - An[i+1] )
#print("dis:",dis)
for j in range(N):
    #print("j:",j)
    if j == 0:
        if (0 <= An[j] <= An[j + 1]) or (0 >= An[j] >= An[j + 1]):
            print(dis)
        else:
            print(dis - abs(An[j] - An[j + 1]) - abs(An[j]) + abs(An[j + 1]) )
    else:
        print(dis - abs(An[j] - An[j + 1]) - abs(An[j] - An[j - 1]) + abs(An[j - 1] - An[j + 1]) )

Measured memory_bytes: 14048
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870
struct pig
{
    int x,y;
}info[200100];
int cnt,n,a[200100],c[200100],xo,xt,yo,yt,len,num;
long double ans;
bool cmp1(pig a,pig b)
{
    return a.y < b.y;
}
bool cmp(pig a,pig b)
{
    if(a.x == b.x)return a.y > b.y;
    return yo < yt ? a.x < b.x : a.x > b.x;
}
int main()
{
    scanf("%d%d%d%d",&xo,&yo,&xt,&yt);if(xt < xo)swap(xo,xt),swap(yo,yt);
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)scanf("%d%d",&info[i].x,&info[i].y);
    sort(info + 1,info + 1 + n,cmp);
    len=0;  c[0]=-0x7fffffff;
    for(int i = 1;i <= n;i++)
    {
        if(info[i].x > max(xt,xo) || info[i].y > max(yt,yo) || info[i].y < min(yo,yt) || info[i].x < min(xo,xt))continue;
        int tmp;
        if(info[i].y>c[len]) tmp = ++len;
        else tmp = lower_bound(c + 1,c + 1 + len,info[i].y) - c;
        c[tmp]=info[i].y;
    }
    ans = (long double)(abs(xt - xo) + abs(yt - yo)) * 100 - (20 - 5 * pi) * len;
    if(len == min(abs(xt - xo),abs(yt - yo)) + 1)ans += 5 * pi;
    printf("%.15Lf\n",ans);
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>

void turnNorth(int *d){
    int one = d[0];
    d[0] = d[1];
    d[1] = d[5];
    d[5] = d[4];
    d[4] = one;
}

void turnEast(int *d){
    int one = d[0];
    d[0] = d[3];
    d[3] = d[5];
    d[5] = d[2];
    d[2] = one;
}

void turnWest(int *d){
    int one = d[0];
    d[0] = d[2];
    d[2] = d[5];
    d[5] = d[3];
    d[3] = one;
}

void turnSouth(int *d){
    int one = d[0];
    d[0] = d[4];
    d[4] = d[5];
    d[5] = d[1];
    d[1] = one;
}

void turnRight(int *d){
    int two = d[1];
    d[1] = d[2];
    d[2] = d[4];
    d[4] = d[3];
    d[3] = two;
}

void turnLeft(int *d){
    int two = d[1];
    d[1] = d[3];
    d[3] = d[4];
    d[4] = d[2];
    d[2] = two;
}

void resetDice(int *d){
    for(int i=0; i<6; i++){
        d[i] = i + 1;
    }
}

int main(){
    int dice[6] = {1, 2, 3, 4, 5, 6};
    int n, ans;
    std::string rot;

    while(std::cin >> n){
        if(!n){
            break;
        }
        ans = 1;
        resetDice(dice);
        while(n--){
            std::cin >> rot;
            if(rot == "North"){
                turnNorth(dice);
            }
            else if(rot == "East"){
                turnEast(dice);
            }
            else if(rot == "West"){
                turnWest(dice);
            }
            else if(rot == "South"){
                turnSouth(dice);
            }
            else if(rot == "Right"){
                turnRight(dice);
            }
            else if(rot == "Left"){
                turnLeft(dice);
            }
            ans += dice[0];
        }
        std::cout << ans << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1208
//Decision's template
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<set>
using namespace std;

#define DP_maxn 16
#define maxn 1000000+10
#define INF 1000000007
#define mod 1000000007
#define mst(s,k) memset(s,k,sizeof(s))
#define eps 1e-12

typedef long long ll;

struct Edge{
    int from,to,dist;
    Edge(int u,int v,int d):from(u),to(v),dist(d){}
};

/*-------------------------------template End--------------------------------*/

bool flag = 0;
int n,ans = 400007;
char s[400007];
int sum[400007];
vector<int> q1,q2;

bool check(){
	bool res = 0;
	int i;
	for(i = 0;i<n;i++){
		if(s[i] == '#') continue;
		else break;
	}
	for(i;i<n;i++){
		if(s[i] == '.') continue;
		else break;
	}
	if(i == n) res = 1;
	else res = 0;
	return res;
}

int main(){
	cin>>n>>s;
	mst(sum,0);
	for(int i = 0;i<n;i++){
		if(s[i] == '#' && flag == 0){
			q1.push_back(i);
			flag = 1;
		}
		else if(s[i] == '.' && flag == 1){
			q2.push_back(i - q1[q1.size() - 1]);
			flag = 0;
		}
		else continue;
	}
	if(q1.size() == 0){
		cout<<"0"<<endl;
		return 0;
	}
	else if(check()){
		int t = 0;
		for(int i = 0;i<n;i++){
			if(s[i] == '#') t++;
			else break;
		}
		cout<<min(t,n-t)<<endl;
		return 0;
	}
	if(s[n-1] == '#') q2.push_back(n - q1[q1.size() - 1]);
	else q2.push_back(0);
	sum[q2.size() - 1] = q2[q2.size() - 1];
	for(int i = q2.size() - 1;i>=1;i--){
		sum[i - 1] = sum[i] + q2[i - 1];
	}
	ans = n - q1[0] - sum[0];
	for(int i = 1;i<q2.size();i++){
		ans = min((n-q1[i]-sum[i]) + (sum[0] - sum[i]),ans);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

int main() {
  
  int N , M ;
  cin >> N >> M ;
  vector<int> A(N);
  
  rep(i,N) cin >> A.at(i) ;
  sort(A.begin(),A.end()) ;
  ll B = 100000000000000 ;
  if( N == 1 && M == A.at(0) ){
    cout << "POSSIBLE" << endl;
    return 0 ;
  }
  //cout << A.at(N-1) << endl;
  for(int i = N-1 ; i > 0 ; i-- ) {
    ll C = gcd(A.at(i),A.at(i-1)) ;
    //cout << C << endl ;
    B = min(C,B) ;
}
  //cout << B << endl  ;
  if( M%B == 0 && A.at(N-1) >= M ) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 640
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let r: usize = read();
    let d: usize = read();
    let mut x: usize = read();

    for _ in 0..10 {
        x = r * x - d;
        println!("{}", x);
    }
}

Measured memory_bytes: 4352
n,a,b = map(int,input().split())
x = list(map(int,input().split()))
count = 0
for i in range(n-1):
    if a*(x[i+1] - x[i]) > b:
        count += b
    else:
        count += a*(x[i+1] - x[i])
print(count)


Measured memory_bytes: 62832
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;

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

ll dp[102][4][4][4];

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

    dp[0][3][3][3] = 1;
    for(int len=0;len<n;len++){
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                for(int k=0;k<4;k++){
                    if(dp[len][i][j][k]==0) continue;

                    for(int a=0;a<4;a++){
                        if(a==2 && i==1 && j==0) continue;
                        if(a==2 && i==0 && j==1) continue;
                        if(a==1 && i==2 && j==0) continue;
                        if(a==2 && i==1 && k==0) continue;
                        if(a==2 && j==1 && k==0) continue;

                        dp[len+1][a][i][j] += dp[len][i][j][k];
                        dp[len+1][a][i][j] %= MOD;
                    }

                }
            }
        }
    }

    ll ans=0;
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                ans += dp[n][i][j][k];
                ans %= MOD;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
a,b = (int(i) for i in input().split())

def solve(n):
  if n%4 == 3:
    return 0
  elif n%4 == 1:
    return 1
  elif n%4 == 2:
    return 1 ^ n
  elif n%4 == 0:
    if n == 0: return 0
    else:
      return n
    

print(solve(b)^solve(a-1))


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

int main() {
	int N,K,start=0,min;
	cin >> N;
	cin >> K;

	int number[100000];
	for (int i = 0; i < N; i++) {
		cin >> number[i+1];
		if (number[i+1] == 1) start = i+1;
	}

	if (start <= K || start >= K) {
		min = 1 + ((N-K) / (K-1));
		if ((N - K) % (K - 1) != 0) {
			min += 1;
		}
	}
	else {
		min = 1 + (N - start + 1 - K) / (K - 1) + 1 + (start - K) / (K - 1);
		if ((N - start + 1 - K) % (K - 1) != 0) {
			min += 1;
		}
		if ((start - K) % (K - 1) != 0) {
			min += 1;
		}
	}
	cout << min << endl;
	system("pause");
}

Measured memory_bytes: 888
# E - Active Infants

n = int(input())
a = list(map(int, input().split()))
assert len(a) == n

# 添字のリスト
p = list(range(n))
p.sort(key=lambda i: a[i])

# dp[(j, i)] = 位置jから幅iの区間に小さい方からi個を配置したときの最大うれしさ
dp = {(j, 0): 0 for j in range(n + 1)}

for i in range(n):
    for j in range(n - i):
        dp[(j, i + 1)] = \
            max(dp[(j,     i)] + a[p[i]] * abs(p[i] - (j + i)),
                dp[(j + 1, i)] + a[p[i]] * abs(p[i] - j))

print(dp[(0, n)])


Measured memory_bytes: 315300
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i=a;i<(int)(n);i++)
using namespace std;
int main(){
  int n,sum,a[10000];
  cin>>n;
  sum=0;
  rep(i,0,n){
    cin>>a[i];
	sum+=a[i]-1;  
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int t = a / k;
        int p = a % k;
        if(p == 0 || (t + 1) * k <= b){
            System.out.println("OK");
        }else{
            System.out.println("NG");
        }
    }
}

Measured memory_bytes: 27000
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        M: usize,
        A: [usize; M]
    }
    // Aを降順ソート
    let mut A = A;
    A.sort_by(|a, b| b.cmp(a));
    // 数字を表現するのに必要なマッチ本数
    let num = vec![0,2,5,5,4,5,6,3,7,6];
    // dp : i本のマッチで表現可能な最大桁数
    let mut dp = vec![None; N+1];
    // dp初期化
    dp[0] = Some(0);
    for i in 0..M{
        if num[A[i]]<=N{
            dp[num[A[i]]] = Some(1);
        }
    }
    // dp更新
    for i in 1..N+1{
        for j in 0..M{
            if i >= num[A[j]] && dp[i-num[A[j]]]!=None{
                dp[i] = max(dp[i], dp[i-num[A[j]]].map(|x| x+1));
            }
        }
    }
    // 復元
    let mut N = N;
    let mut ans = vec![0; dp[N].unwrap()];
    for i in 0..dp[N].unwrap(){
        for j in 0..M{
            if N>=num[A[j]] && dp[N-num[A[j]]]==dp[N].map(|x| x-1){
                ans[i] = A[j];
                N -= num[A[j]];
                break
            }
        }
    }
    for a in ans{
        print!("{}", a);
    }
}

Measured memory_bytes: 4352
n = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

whole = factorization(n)

count = 0

if whole == [[1, 1]]:
  print(count)
  exit()

#print(whole)
for s in whole:
  #print(s)
  c = 0
  for i in range(1, s[1] + 1):
    shou = n / (int(s[0]) ** (i * (i + 1) / 2))
    seisuu = n // (int(s[0]) ** (i * (i + 1) / 2))
    if shou == seisuu:
      #print(shou, seisuu)
      c += 1
    else:
      break
  count += c

print(count)


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back

const int MOD=1e9+7;
const int MAX=2020;
vll modfac(MAX,1);

ll modpow(ll m,ll n,ll p) {
  if(n==0) return 1;
  ll res=modpow(m,n/2,p);
  if(n%2==0) res=(res*res)%p;
  else res=(((res*res)%p)*m)%p;
  return res;
}

ll modinv(ll m,ll p) {
  return modpow(m,p-2,p);
}

ll modcom(ll n,ll r,ll p) {
  for(int i=1;i<=MAX;i++) {
    modfac[i]=modfac[i-1]*i%p;
  }
  return ((modfac[n]*modinv(modfac[r],p))%p*modinv(modfac[n-r],p))%p;
}

int main() {
  ll S; cin>>S;
  ll ans=0;

  for(ll i=1;3*i<=S;i++) {
    ans+=modcom(S-3*i+i-1,i-1,MOD);
    ans%=MOD;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)
#define large pow(10,9)+7

//template functions
/////////////////////////
long Comb(long N,long M){// nCm
    long ans=1;
    for(long i=N;i>N-M;i--){
        ans=ans*i;
    }
    for(long i=M;i>0;i--){
        ans=ans/i;
    }
    return ans;
}
long Perm(long N,long M){// nPm
    long ans=1;
    for(long i=N;i>N-M;i--){
        ans=ans*i;
    }
    return ans;
}
long Divup(long a,long b){
    return (a+b-1)/b;
}
/////////////////////////



//Answer


int main() {

long count;
long N,K;
cin>>N>>K;

vector<int> A(N);
for(long i=0;i<N;i++){
cin>>A.at(i);
}
sort(A.begin(),A.end());
long ok=A.at(N-1);
long ng=0;
long mid=(ok+ng)/2;
while(abs(ok-ng)>1){
  	mid=(ok+ng)/2;
    long count=0;
    for(long i=0;i<N;i++){
        count+=Divup(A.at(i),mid)-1;
    }
    if(count<=K){
        ok=mid;
    }else{
        ng=mid;
    }
}

cout<<ok<<endl;
}




//高精度要求→しつこくlong doubleでcast　出力はprintf("20.20Lf")とかで
//printf("%a.bLf")のとき、a-b-1が整数部分の桁数。
/*配列系の書き方
long N;
cin>>N;
vector<long> p(N);
for(long i=0;i<N;i++){
cin>>p.at(i);
}

vector<int> d(102,1);
*/


Measured memory_bytes: 3984
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

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

const ll mod = 1e9 +7;

vector<long long> sieve(const long long& n)
{
    vector<long long> v(n + 1);
    vector<bool> c(n + 1, 1);
    vector<long long> ret;
    for (long long i = 2; i <= n; ++i)
    {
        if (c[i])
        {
            for (long long j = 2 * i; j <= n; j += i)
            {
                c[j] = 0;
            }
            ret.push_back(i);
        }
    }
    return ret;
}

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

int main() {
    
    ll a, b;
    
    cin >> a >> b;
    
    ll n = gcd(a, b);
    
    ll mn = sqrt(n) + 1;
    
    vector<ll> p = sieve(mn);
    
    ll ret = 1;
    
    for (ll i = 0; i < p.size(); ++i)
    {
        if ((n % p[i]) == 0ll)
        {
            while (n % p[i] == 0) {
                n /= p[i];
            }
            ret++;
        }
    }
    if (n != 1ll)
    {
        ret++;
    }
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 9336
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

bool bad[11];

int n, k;

bool ok(int x)
{
	while(x)
	{
		int y = x%10;
		x /= 10;
		if(bad[y]) return false;
	}
	return true;
}

int main()
{
	scanf("%d %d", &n, &k);
	for(int i = 1; i<= k; i++)
	{
		int x; scanf("%d", &x);
		bad[x] = true;
	}
	for(int x = n; ; x++)
	{
		if(ok(x))
		{
			printf("%d\n", x);
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>
const int N=1e5+10;
int rnd(){
    static int a=234892734,b=880701;
    a^=b;
    b+=a;
    return a;
}
struct node{
    node* l;
    node* r;
    int num;
    int pri;
    int size;
    long long int val;
    node(int a,int b){
        size=1;
        num=a;
        val=b;
        pri=rnd();
        l=r=nullptr;
    }
    void pull(){
        size=1;
        if(l)size+=l->size;
        if(r)size+=r->size;
        return ;
    }
    void out(){
        printf("%d %lld\n",num,val);
    }
};
node* merge(node* a,node* b){
    if(!a)return b;
    if(!b)return a;
    if(a->pri>b->pri){
        a->r=merge(a->r,b);
        a->pull();
        return a;
    }
    else{
        b->l=merge(a,b->l);
        b->pull();
        return b;
    }
}
void split(node* s,int n,long long int x,node*&a,node*&b){
    if(s){
        if(x>s->val||(x==s->val&&n<s->num)){
            b=s;
            split(s->l,n,x,a,b->l);
            b->pull();
        }
        else{
            a=s;
            split(s->r,n,x,a->r,b);
            a->pull();
        }
    }
    else a=b=nullptr;
    return ;
}
node* find(node* s,int n){
    int temp=s->l?s->l->size+1:1;
    if(n>temp)return find(s->r,n-temp);
    else if(n==temp)return s;
    else return find(s->l,n);
}
int main(){
    int n,q,k,t;
    long long int a[N];
    node* root=nullptr,*l,*r,*mid,*temp;
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++){
        root=merge(root,new node(i,0));
        a[i]=0;
    }
    while(q--){
        scanf("%d",&k);
        if(k==0){
            scanf("%d%d",&k,&t);
            split(root,k,a[k],l,r);
            split(l,k-1,a[k],root,temp);
            a[k]+=t;
            temp->val=a[k];
            split(root,k,a[k],l,mid);
            root=merge(l,temp);
            root=merge(root,mid);
            root=merge(root,r);
        }
        else{
            scanf("%d",&t);
            mid=find(root,t);
            mid->out();
        }
    }
}


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

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    vi a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(ALL(a));
    if(a[0] == a[1] && a[2] != a[1]) cout << "Yes" << endl;
    else if(a[2] == a[1] && a[0] != a[1]) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,t;
  int a,b=0,ans=0;
  cin>>n>>t;
  ans=n*t;
  for(int i=0;i<n;i++){
    cin>>a;
    if(b>a) ans-=(b-a);
    b=a+t;
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 500030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

int main()
{

int n,m;
cin>>n>>m;
vector<int> v(n);
rep(i,0,n)
v[i]=-1;
bool b=false;
vector<pair<int,int> > vp;
rep(i,0,m)
{
	int x,y;
	cin>>x>>y;
	vp.push_back({x,y});
}
sort(vp.begin(),vp.end());
if(n==1)
{
	if(!m)
	{
		cout<<0;
		return 0;
}
   else	if(m==1)
	{
		cout<<vp[0].se;
		return 0;
	}
else
{

	rep(i,1,m)
	{
		if(vp[i].se!=vp[i-1].se)
		{

		cout<<"-1";
		return 0;}
		
	}
	cout<<vp[0].se;
	return 0;
}
}
else
{

rep(i,0,m)
{
	int x=vp[i].fi;
	int y=vp[i].se;
	if(x==1)
	{
		if(y<=0)
		b=true;
		if(v[x-1]==-1||v[x-1]==y)
		v[x-1]=y;
		else
		b=true;
	}
	else
	{
		if(v[x-1]==-1||v[x-1]==y)
		v[x-1]=y;
		else
		b=true;
		
	}
	
}
rep(i,0,n)
{
	if(!i)
	{
		if(v[i]==-1)
		v[i]=1;
		if(v[i]<=0)
		b=true;
	}
	else
	{
		if(v[i]==-1)
		v[i]=0;
	}
}
if(b)
cout<<"-1";
else
{
	rep(i,0,n)
	cout<<v[i];
}
}}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
using namespace std;

int A[300][300] = {0};
set<int> removedSet;

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

int main()
{
    // 整数の入力
    long long N,A,B,C,D,i;
    cin >> N;
    for (int i = 0;i<N;i++){
        cin >> A >> B >> C >> D;
        if (A < B){
            cout << "No" << endl;
        }else if (D < B){
            cout << "No" << endl;
        }else {
            long long gcd_of_BD = gcd(B,D);
            long long amari = (A - C) % gcd_of_BD;
            long long min_zaiko;
            if (A <= C){
                min_zaiko = A - B;
            }else if (amari == 0){
                min_zaiko = C + gcd_of_BD - B;
            }else{
                min_zaiko = C + amari - B;
            }
            // cout << "gcd" << gcd_of_BD << endl;
            // cout << "amari:"<< amari << endl;
            // cout << "min_zaiko:" << min_zaiko << endl;
            if (min_zaiko >= 0){
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }

            // if (min_zaiko + D >= B){
            //     cout << "Yes" << endl;
            // }else{
            //     cout << "No" << endl;
            // }
        }
    }
    return 0;
}

Measured memory_bytes: 256
/* AUTHOR :  SHIVANK JAIN */

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false)
#define itt cin.tie(0)
#define now cout.tie(0)

using namespace std;

#define ll long long
#define li long int

#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define reprev(i,n,a) for(int i=n;i>=a;i--)
#define endl "\n"

#define vi vector<int>
#define vll vector<ll>
#define vpi vector< pair<int , int> >
#define mapi map<int , int>
#define mapll map<ll ,ll >
#define seti set<int> 

#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
#define sort(v) sort(v.begin() , v.end())

#define BIG 1000000007
int gcd(int a, int b) 
{ // builtin function __gcd(a,b)
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
int main(){

     fast;itt;now;
 
//    #ifndef ONLINE_JUDGE
//    // for getting input from input.txt
//    freopen("input.txt", "r", stdin);
//    // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
//    #endif
    
     string n;  cin>>n;
     int f = 0;
     rep(i,0,n.size())
      if(n[i] - '0' == 7){
      	f = 1;
      	break;
	  }
	  
	  if(f == 0)
	   cout<<"No"<<endl;
	  else
	   cout<<"Yes"<<endl; 
}

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

int main()
{
	int n = 0;
	int r = 0;
	int p = 0;
	int c = 0;

	int deck[50] = {};
	int tmp[50] = {};

	while (true)
	{
		cin >> n;
		cin >> r;
		if (n == 0 && r == 0)break;
		for (int i = 0; i < n; i++)
		{
			deck[i] = n - i;
		}

		for (int i = 0; i < r; i++)
		{
			cin >> p;
			cin >> c;

			for (int j = 0; j < p - 1; j++)
			{
				tmp[j] = deck[j];
			}

			for (int j = 0; j < c; j++)
			{
				deck[j] = deck[p - 1 + j];
			}


			for (int j = 0; j < p - 1; j++)
			{
				deck[c + j] = tmp[j];
			}
		}
		cout << deck[0] << endl;
	}
	return 0;
}

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

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(b / a, c) << endl;
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  int b;
  int check;
  b = (s[0]-'0')*100+(s[1]-'0')*10+(s[2]-'0');
  for(int i=1;i<10;i++){
    check = i*100+i*10+i;
    if(b<=check){
      cout << check << endl;
      return 0;
    }
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 11
#define inf 1<<29
#define linf (1e16)
#define eps (1e-8)
#define Eps (1e-12)
#define mod 1000000007
#define pi acos(-1.0)
#define phi (1.0+sqrt(5.0))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define pld(a) printf("%.10Lf\n",(ld)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define Unique(v) v.erase(unique(all(v)),v.end())
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpi;

int n,m;
int p[MAX][MAX];

int cal(int a,int b,int c,int d){
  int h = inf,sum = 0;
  FOR(i,c,d+1)h=min(h,min(p[a][i],p[b][i]));
  FOR(i,a,b+1)h=min(h,min(p[i][c],p[i][d]));
  FOR(i,a+1,b){
    FOR(j,c+1,d){
      if(h<=p[i][j])return 0;
      sum+=(h-p[i][j]);
    }
  }
  return sum;
}

int solve(){
  int ans = 0;
  FOR(i,0,n)
    FOR(I,i+2,n)
      FOR(j,0,m)
        FOR(J,j+2,m)
          ans = max(ans,cal(i,I,j,J));
  return ans;
}

int main()
{
  while(cin>>n && cin>>m && n){
    FOR(i,0,n)
      FOR(j,0,m)cin>>p[i][j];
    cout<<solve()<<endl;
  }
  return 0;
}


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

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define eb          emplace_back
#define	endl		'\n' 
#define max(a,b)	((a)>(b)?(a):(b))
#define min(a,b)	((a)<(b)?(a):(b))
#define vi          vector<int>
#define vii         vector<pair<int, int> >
#define mp          make_pair
#define mem1(a)     memset((a),-1,sizeof(a))
#define all(a)      (a).begin(),(a).end()
#define vs          vector<string>
#define F           first
#define S           second
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    (a)*((b)/gcd((a),(b)))
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mi          map<int,int>
#define sz(x)       (ll)(x).size()
#define rep(i,a,b)  for(int i=(a);i<(b);i++)
#define pii         pair<int,int>
vector<vector<int>> adj(100001);
vi order(100001);
vector<bool> used(100001);
int k;
int dfs(int v)
{
	used[v]=true;
	for(auto u : adj[v])
	{
		if(!used[u])
			dfs(u);
	}
	order[k++]=v;
	return 0;
}

int solve()
{
	int n,m;
	cin>>n>>m;
	k=0;
	adj.resize(n+1);
	//order.resize(n+1);
	used.resize(n+1);
	int a,b;
	rep(i,0,m)
	{
		cin>>a>>b;
		adj[a].pb(b);
	}
	for(int i=1;i<=n;i++)
	{
		if(!used[i])
			dfs(i);
	}
	int  dp[n+1];
	rep(i,0,n+1)
	dp[i]=0;
	//cout<<k<<endl;
	// dp[i]= maximum no of points visited before it
	//rep(i,0,k)
	//cout<<order[i]<<" ";
	for(int i=n-1;i>=0;i--)
	{
		int v=order[i];
		for(auto u : adj[v])
		{
			dp[u]=max(dp[u],dp[v]+1);
		}
	}
	int ans=0;
	rep(i,0,n+1)
	{
		//cout<<dp[i]<<" ";
		ans=max(ans,dp[i]);
	}
	cout<<ans;
    return 0;
}
signed main()
{
    FAST
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); 
        freopen("output.txt", "w", stdout); 
    #endif 
    int t=1;
    //cin>>t;
    while(t)
    {
        solve();
        t--;
    }
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}

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

int main(){
    char c;
    cin >> c;
    if(c >= 'a' && c <= 'z') cout << "a" << endl;
    else cout << "A" << endl;
    return 0;
}

Measured memory_bytes: 3588
using System;


class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int k = int.Parse(input[1]);
        int ans = 0;
        if (n % k == 0) {ans = 0; }
        else { ans = 1; }
        Console.WriteLine(ans);

    }
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(c) (c).begin(), (c).end()

static constexpr int64_t MOD = 1'000'000'007;

inline int64_t add_mod(int64_t a, int64_t b) { return (a + b) % MOD; }
inline int64_t sub_mod(int64_t a, int64_t b) { return (a - b + MOD) % MOD; }
inline int64_t mul_mod(int64_t a, int64_t b) { return (a * b) % MOD; }

template <typename Int>
vector<int64_t> make_cumsum(const vector<Int>& v) {
    vector<int64_t> cumsum(v.size()+1);
    for (size_t i = 1; i < cumsum.size(); ++i) {
        cumsum[i] = add_mod(cumsum[i-1], v[i-1]);
    }
    return cumsum;
}

// [first, last] の和を返す
inline int64_t sum_of(const vector<int64_t>& cumsum, int first, int last) noexcept {
    return sub_mod(cumsum[last+1], cumsum[first]);
}

int main() {
    int S; cin >> S;
    int N = (S+2)/3;

    // dp[n][s]: n個の整数を使ってsを作る作り方の数
    vector dp(N+1, vector(S+1, int()));
    vector<vector<int64_t>> cumsum(N+1);

    dp[0][0] = 1;
    for (int n = 1; n <= N; ++n) {
        cumsum[n-1] = make_cumsum(dp[n-1]);
        for (int s = 3; s <= S; ++s) {
            dp[n][s] = sum_of(cumsum[n-1], 0, s-3);
        }
    }

    int64_t ans = 0;
    REP(n, N+1) ans = add_mod(ans, dp[n][S]);
    cout << ans << endl;
}


Measured memory_bytes: 18964
# coding: utf-8


def solve(*args: str) -> str:
    s, t = args[0].split()
    a, b = map(int, args[1].split())
    u = args[2]

    if u == s:
        a -= 1
    elif u == t:
        b -= 1

    return '{} {}'.format(a, b)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

int main() {
  int n;
  cin >> n;
  
  vector<int> b(n-1);
  
  for(int i=0; i < n-1; i ++){
    cin >> b.at(i);
  }
  
  int sum = b.at(0)+b.at(n-2);
  
  if( n > 2){
    for(int i = 0; i < n-2 ; i ++){
      if(b.at(i) < b.at(i+1)){
        sum += b.at(i);
      }
      else{
        sum += b.at(i+1);
      }
    }
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		System.out.println(Math.min(a, b) + Math.min(c, d));
	}
}

Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long A = scan.nextInt();
		long B = scan.nextInt();

		System.out.println(lcm(A,  B));
	}

	private static long gcd(long m, long n) {
		// 入れ替え
		if(m < n) {
			return gcd(n, m);
		}
		if(n == 0) {
			return m;
		}
		return gcd(n , m % n);
	}

	private static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

}

Measured memory_bytes: 21844
using System;
using System.Linq;

namespace aizu
{
    public class OnlineJudge
    {
        static void Main()
        {
            int input;
            while((input = int.Parse(Console.ReadLine())) != 0){
                Console.WriteLine(Enumerable.Range(1, input >> 2).Select(p => int.Parse(Console.ReadLine())).Sum());
            }
        }
    }
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int A[200000];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int K, N, ans;
	cin>>K>>N;
	for(int i=0;i<N;i++) cin>>A[i];
	ans=K-(A[N-1]-A[0]);
	for(int i=1;i<N;i++) ans=max(ans,A[i]-A[i-1]);
	cout<<K-ans<<'\n';
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int i,j,k,x,y,z,l,m,n,count1=0,count2=0;
int gcd(int,int);
void A(void);
void B(void);
void C(void);
void D(void);
void E(void);
void F(void);

int main(void){
    D();
}

void D(){
    long long int k;
    int next,d=0;
    int t=0,t2=0;
    cin>>n>>k;
    vector<int> vec(n),vec2(n,0);
    for(i=0;i<n;i++){
        cin>>vec[i];
    }
    next=1;
    if(k>n){
    while(count1!=1){
        next=vec[next-1];
        vec2[next-1]++;
        if(d<1){
            t2++;
            cerr<<t2<<" ";
        }
        if(d>=1)t++;
        if(vec2[next-1]==3){
            d++;
        }
        if(vec2[next-1]==4){
            count1++;
        }
    }
    t2=t2-t-1;
    cerr<<"t:"<<t<<" "<<"t2:"<<t2<<endl;
    k=(k-t2)%t;
    cerr<<k+t2<<endl;
    next=1;
    for(i=0;i<k+t2;i++){
        next=vec[next-1];
    }
    cout<<next<<endl;
    }else{
        next=1;
        for(i=0;i<k;i++){
            next=vec[next-1];
        }
        cout<<next<<endl;
    }
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int K;
  cin >> K;
  
  int Q;
  cin >> Q;
  
  vector<int> A(Q); // N個の数学の点数データ
  for (int i = 0; i < Q; i++) {
    cin >> A.at(i);
  }
  
  vector<int> Point(N); 
  for (int i = 0; i < N; i++) {
   Point.at(i) = K;
  }
  
  vector<int> minusPoint(N); 
  for (int i = 0; i < N; i++) {
   minusPoint.at(i) = Q;
  }
  /*
   for (int i = 0; i < Q; i++) {
   for (int j = 0; j < N; j++) {
     if(A.at(i)==j+1){}else{
     Point.at(j)=Point.at(j)-1;
     }
  }
  }
  */
    for (int i = 0; i < Q; i++) {
   minusPoint.at(A.at(i)-1)--;   
   }
  for (int i = 0; i < N; i++) {
   Point.at(i) = Point.at(i) - minusPoint.at(i);   
   }
  
  for (int i = 0; i < N; i++) {
  if(Point.at(i) <= 0){
    cout << "No"  << endl;
  }else{
  cout << "Yes"  << endl;
  }
  }
  
  
}

Measured memory_bytes: 1792