akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
int main(){

  char s[200],p[100];
  
  scanf("%s", s);
  scanf("%s", p);
  
  int a,b;
  a = strlen(s);
  b = strlen(p);

  int i,j,k;
  k = 0;
  
  for ( i = 0 ; i < a ; i++ ){
    s[ i + a ] = s[i];
  }
  
  for ( i = 0 ; i <= a ; i++ ){

    if ( a == i ){
      printf("No\n");
      break;
    }
    
    for ( j = 0 ; j <= b ; j++ ){
      if ( j == b ){
	printf("Yes\n");
	k = 1;
	break;
      }
      if ( s[ i + j ] != p[j] ) break;
    }
    if ( k == 1 ) break;
  }

  return 0;
  
}

Measured memory_bytes: 524
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val N = rd.readInt()
    val A = rd.readLongArray()

    var sum = 0L
    for (i in 1 until N) {
        val da = A[i-1] - A[i]
        if (da > 0L) {
            A[i] += da
            sum += da
        }
    }

    val ans = sum
    println(ans)
}


//val rd = debug.Reader("abc", "176", "c", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
data class To(val idx: Int, val cost: Long)
typealias ALI = ArrayList<Int>
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readDouble: () -> Double = { br.readLine().toDouble() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readIntArray: () -> IntArray = { readListInt().toIntArray() }
    val readLongArray: () -> LongArray = { readListLong().toLongArray() }
    val readListStringCol: (Int) -> List<String> = { N -> (0 until N).map { readString() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListIntCols: (Int) -> List<List<Int>> = { N -> (0 until N).map { readListInt() } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val readListLongCols: (Int) -> List<List<Long>> = { N -> (0 until N).map { readListLong() } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 65752
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N; cin>>N;
  vector<pii> P(N);
  rep(i,0,N){
    int X,L;
    cin>>X>>L;
    P[i].first=X+L;
    P[i].second=X-L;
    }
  sort(ALL(P));
  vi A(N),B(N);
  rep(i,0,N){
    A[i]=P[i].first;
    B[i]=P[i].second;
    }
  vi dp(N);
  dp[0]=1;
  rep(i,1,N){
    int K=disup(A,B[i]);
    if(K>0){
      K--;
      dp[i]=max(dp[K]+1,dp[i-1]);
      }
    else
      dp[i]=dp[i-1];
    }
  int ans=0;
  rep(i,0,N) ans=max(ans,dp[i]);
  cout<<ans<<endl;
  }



Measured memory_bytes: 4224
/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define all(a)      (a).begin(),(a).end()
#define si(x)       (int)((x).size())
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
#define se second 
#define endl        '\n'
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mem(a,x)          memset(a,x,sizeof(a))

// const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=1000000+6;
#define M_PI           3.14159265358979323846

// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
// int x2[]={+0,+0,+1,-1,-1,+1,-1,+1};
// int y2[]={-1,+1,+0,+0,+1,+1,-1,-1};
// int x2[]={-2,-2,-1,-1,+1,+1,+2,+2};
// int y2[]={-1,+1,-2,+2,-2,+2,-1,+1};

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===

void inp(ll *arr,ll n)
{
  for(int i=0;i<n;i++)
    cin>>arr[i];
}

int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //  #ifndef ONLINE_JUDGEc
    //   freopen ("INPUT.txt" , "r" , stdin);
    //   freopen ("OUTPUT.txt", "w" , stdout);
    // #endif 
    ll n;cin>>n;
    ll tot=1;
    f(i,1,n+1)
    {
      tot*=10;
      tot%=mod;
    }
    ll x=1,y=1;
    f(i,1,n+1)
    {
      x*=9;x%=mod;
      y*=8;y%=mod;
    }
    ll ans=tot-x;
    ans+=mod;ans%=mod;
    ans-=x;ans+=mod;ans%=mod;
    ans+=y;ans+=mod;ans%=mod;
    ans+=mod;
    ans%=mod;cout<<ans;
} 

Measured memory_bytes: 3648
#include <stdio.h>

int main(int argc, char const *argv[]) {

  long long int A, B, K;
  scanf("%lld", &A);
  scanf("%lld", &B);
  scanf("%lld", &K);

  if (K <= A) {
    A = A - K;
  }else{
    B = (A + B) - K;
    A = 0;

    if (0 > B) {
      B = 0;
    }

  }

  printf("%lld %lld\n", A, B);

  return 0;
  
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

struct Union_find{
	vector<int> par;
	vector<int> rank;
	Union_find(int p){
		par = vector<int>(p + 1);
		rank = vector<int>(p + 1);
		for(int i = 1; i <= p; i++){
			par[i] = i;
		}
	}
	int find(int x){
		if(par[x] == x)
			return x;
		else{
			return par[x] = find(par[x]);
		}
	}
	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}
	bool same(int x, int y){
		return find(x) == find(y);
	}
};


int main(){
	int n, k, l, ans = 0;
	cin >> n >> k >> l;
	Union_find load(n), rail(n);
	for(int i = 0; i < k; i++){
		int x, y;
		cin >> x >> y;
		load.unite(x, y);
	}
	for(int i = 0; i < l; i++){
		int x, y;
		cin >> x >> y;
		rail.unite(x, y);
	}
	vector<pair<int, int>> pa(n + 1);
	map<pair<int, int>, int> ma;
	for(int i = 1; i <= n; i++){
		pa[i].first = load.find(i);
		pa[i].second = rail.find(i);
		ma[pa[i]]++;
	}
	for(int i = 1; i <= n; i++){
		cout << ma[pa[i]];
		if(i < n){
			cout << " ";
		}else{
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 16640
import java.util.Scanner;
public class Main {
private static Scanner s = new Scanner(System.in);
public static void main(String[] args) {
	double[] p1 = new double[2],p2 = new double[2];
	int n = s.nextInt();
	p1[0] = 0.0;
	p1[1] = 0.0;
	p2[0] = 100.0;
	p2[1] = 0.0;
	System.out.println(p1[0] + " " + p1[1]);
	koch(n,p1,p2);
	System.out.println(p2[0] + " " + p2[1]);
}

static void koch(int n,double[] p1,double[] p2) {
	if(n == 0) return;

	double[] u = new double[2];
	double rot = Math.toRadians(60);
	double[] s = new double[2],t = new double[2];
	s[0] = (2.0 * p1[0] + p2[0]) / 3.0;
	s[1] = (2.0 * p1[1] + p2[1]) / 3.0;
	t[0] = (2.0 * p2[0] + p1[0]) / 3.0;
	t[1] = (2.0 * p2[1] + p1[1]) / 3.0;
	u[0] = (t[0] - s[0]) * Math.cos(rot) - (t[1] - s[1]) * Math.sin(rot) + s[0];
	u[1] = (t[0] - s[0]) * Math.sin(rot) + (t[1] - s[1]) * Math.cos(rot) + s[1];
	koch(n-1,p1,s);
	System.out.println(s[0] + " " + s[1]);
	koch(n-1,s,u);
	System.out.println(u[0] + " " + u[1]);
	koch(n-1,u,t);
	System.out.println(t[0] + " " + t[1]);
	koch(n-1,t,p2);

}
}



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

mod = 10 ** 9 + 7

a = [0] * (K+1)
for i in range(1,K+1):
    a[i] = pow(K//i, N, mod)
    
for i in range(1,K+1)[::-1]:
    for j in range(2,K//i+1):
        a[i] -= a[i*j]
        a[i] %= mod
        
ans = 0
for i in range(1,K+1):
    ans += (i * a[i]) % mod
    ans %= mod
print(ans)
        

Measured memory_bytes: 11072
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::vector<i64> A;
  tools::read(A, N);
  std::cout << (static_cast<i64>(std::unordered_set<i64>(A.begin(), A.end()).size()) == N ? "YES": "NO") << std::endl;
  return 0;
}

Measured memory_bytes: 9600
# 入力
N = int(input())
witness = [[-1] * N for _ in range(N)]
for i in range(N):
    A = int(input())
    for _ in range(A):
        x, y = map(int, input().split())
        witness[i][x - 1] = y

# 正直者の組を作り判定
ans = 0
for i in range(1, 2 ** N + 1):
    honest = [0] * N
    for j in range(N):
        if int(format(i, 'b').zfill(N)[j]) == 1:
            honest[j] = 1

    is_correct = True
    for j in range(N):
        if honest[j] == 1:
            for k in range(N):
                if witness[j][k] == -1:
                    pass
                elif witness[j][k] != honest[k]:
                    is_correct = False
    if is_correct:
        ans = max(ans, sum(honest))

print(ans)


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int sum = 0;
            
        for (int i = 0; i <= N; i++){
            sum = sum + i;
        }
        
        
            
        int ans = sum;
        
        
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 9684
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


S = input()
T = input()
ans = 0
for i in range(len(S)):
    if S[i] != T[i]:
        ans += 1
print(ans)

Measured memory_bytes: 73796
#include <iostream>
#include <queue>
using namespace std;
struct dta{
  int nw;
  int c;
};
int mp[10][10];
int A[10];
int main(){
  int H,W;cin>>H>>W;
  for(int i = 0; 10 > i; i++){
    for(int j = 0; 10 > j; j++){
      cin>>mp[i][j];
    }
    A[i] = mp[i][1];
  }
  for(int i = 0; 10 > i; i++){
    //i→1にいくための最安コスト
    queue<dta> a;
    for(int j = 0; 10 > j; j++){
      if(i==j){
        continue;
      }
      a.push({j,mp[i][j]});
    }
    while(!a.empty()){
      dta z = a.front();a.pop();
      if(z.c >= A[i])continue;
      if(z.nw == 1)A[i] = min(z.c,A[i]);
      for(int j = 0; 10 > j; j++){
        if(j==z.nw)continue;
        a.push({j,z.c+mp[z.nw][j]});
      }
    }
  }

  int ans = 0;
  for(int i = 0; H > i; i++){
    for(int j = 0; W > j; j++){
      int t;cin>>t;
      if(t == -1)continue;
      ans += A[t];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def dfs a,x,y
	a[x][y]="o" if a[x][y] != "o"
	dfs a,x-1,y if x-1 >= 0 && a[x-1][y] == "."
	dfs a,x+1,y if x+1 < a.length && a[x+1][y] == "."
	dfs a,x,y-1 if y-1 >= 0 && a[x][y-1] == "."
	dfs a,x,y+1 if y+1 < a[0].length && a[x][y+1] == "."
end

while true
	args = gets.split(" ").map{|e|e.to_i}
	break if args[0] == 0 && args[1] == 0
	a=[]
	start=[-1,-1]
	args[1].times{|i|
		a.push gets.chomp
		if a[i].index("@") != nil
			start=i,a[i].index("@")
		end
	}
	dfs a,start[0],start[1]
	count = 0
	a.each{|e|count+=e.count("o")}
	p count
end

Measured memory_bytes: 6148
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;



void solve(){

    int n;
    cin >> n;
    vector<int> s;
    rep(i,n){
        int tmp;
        cin >> tmp;
        s.emplace_back(tmp);
    }
    int q;
    cin >> q;
    vector<int> t;
    rep(i,q){
        int tmp;
        cin >> tmp;
        t.emplace_back(tmp);
    }

    int count=0;
    rep(i,q){
        if(binary_search(s.begin(), s.end(), t[i])) count++;
    }

    cout << count << endl;


}

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



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

int main()
{
	int x;
	cin>>x;
	int i = 4;
	cout << " 3";
	while (i <= x)
	{
		int k = i;
		if (i % 3 == 0)
			cout <<" "<<i;
		else
		{
			while (k != 0)
			{
				if (k % 10 == 3)
				{
					cout <<" "<<i;
					break;
				}
				k = k/10;
			}
		}
		i ++;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3092
def main():
    N, M = map(int, input().split())
    Lw = []
    T = []
    for _ in range(M):
        pi, yi = [int(i) for i in input().split()]
        T.append(pi)
        T.append(yi)
        Lw.append(T)
        T = []
    temp_dict = {}
    answer_dict = {}
    L = Lw.copy()
    L.sort(key=lambda x: x[1])
    for i in range(N):
        temp_dict[str(i+1)] = 1
    for l in L:
        answer_dict[str(l[1])] = temp_dict[str(l[0])]
        temp_dict[str(l[0])] += 1

    for lw in Lw:
        print(str(lw[0]).zfill(6) + str(answer_dict[str(lw[1])]).zfill(6))


if __name__ == "__main__":
    main()


Measured memory_bytes: 54248
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<int Mod> class ModInt {
  int v;
public:
  constexpr ModInt(const long long x = 0) noexcept : v((x % Mod + Mod) % Mod) {};
  constexpr ModInt &operator+=(const ModInt rhs) noexcept {
    v += rhs.v;
    if (v >= Mod)
      v -= Mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt rhs) noexcept {
    if (v < rhs.v)
      v += Mod;
    v -= rhs.v;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt rhs) noexcept {
    v = int(1LL * v * rhs.v % Mod);
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) noexcept {
    long long exp = Mod - 2;
    while (exp) {
      if (exp & 1)
        *this *= rhs;
      rhs *= rhs;
      exp >>= 1;
    }
    return *this;
  }
  constexpr ModInt operator-() const noexcept { return ModInt(-v); }
  constexpr ModInt operator+(const ModInt rhs) const noexcept {
    return ModInt(*this) += rhs;
  }
  constexpr ModInt operator-(const ModInt rhs) const noexcept {
    return ModInt(*this) -= rhs;
  }
  constexpr ModInt operator*(const ModInt rhs) const noexcept {
    return ModInt(*this) *= rhs;
  }
  constexpr ModInt operator/(const ModInt rhs) const noexcept {
    return ModInt(*this) /= rhs;
  }
  constexpr bool operator==(const ModInt rhs) const noexcept {
    return v == rhs.v;
  }
  constexpr bool operator!=(const ModInt rhs) const noexcept {
    return v != rhs.v;
  }
  constexpr ModInt pow(long long exp) const noexcept {
    ModInt res(1), mul(v);
    while (exp) {
      if (exp & 1)
        res *= mul;
      mul *= mul;
      exp >>= 1;
    }
    return res;
  }
  friend ostream &operator<<(ostream &os, const ModInt obj) noexcept {
    return os << obj.v;
  }
  friend istream &operator>>(istream &is, ModInt &obj) noexcept {
    long long tmp;
    is >> tmp;
    obj = ModInt<Mod>(tmp);
    return is;
  }
};
constexpr int MOD = 1000000007;
using mint = ModInt<MOD>;

vector<vector<int>> to;
vector<vector<int>> subtree;
int dfs(int now, int prev) {
  int sum = 1;
  for (auto next : to[now]) {
    if (next == prev)
      continue;
    int res = dfs(next, now);
    subtree[now].push_back(res);
    sum += res;
  }
  if (prev >= 0)
    subtree[now].push_back((int)to.size()-sum);
  return sum;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  to.resize(n);
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  subtree.resize(n);
  dfs(0, -1);
  mint ans = 0;
  rep(i, n) {
    mint res = mint(2).pow(n-1)-1;
    for (auto e : subtree[i])
      res -= mint(2).pow(e)-1;
    ans += res/mint(2).pow(n);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 33280
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
long long int mod = 1e9+7;
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
//////////////////////////////////


int main(){
    int a, b, c; cin >> a >> b >> c;
    cout << max(0, c - (a-b)) << endl;
    
    return 0;
}

// EOF



Measured memory_bytes: 256
#!/usr/bin/env python3
# CGL_2_C: Segments/Lines - Cross Point


def crossing_point(p0, p1, p2, p3):
    x0, y0 = p0
    x1, y1 = p1
    x2, y2 = p2
    x3, y3 = p3

    if x0 != x1 and x2 != x3:
        a0 = (y0 - y1) / (x0 - x1)
        b0 = (x1*y0 - y1*x0) / (x1 - x0)
        a1 = (y2 - y3) / (x2 - x3)
        b1 = (x3*y2 - y3*x2) / (x3 - x2)
        return (b0-b1) / (a1-a0), (a1*b0-a0*b1) / (a1-a0)
    elif x0 != x1:
        a0 = (y0 - y1) / (x0 - x1)
        b0 = (x1*y0 - y1*x0) / (x1 - x0)
        return x2, a0 * x2 + b0
    elif x2 != x3:
        a1 = (y2 - y3) / (x2 - x3)
        b1 = (x3*y2 - y3*x2) / (x3 - x2)
        return x0, a1 * x0 + b1
    else:
        raise ValueError('p0p1 and p2p3 is parallel')


def run():
    q = int(input())

    for _ in range(q):
        x0, y0, x1, y1, x2, y2, x3, y3 = [int(i) for i in input().split()]

        x, y = crossing_point((x0, y0), (x1, y1), (x2, y2), (x3, y3))
        print("{:.10f} {:.10f}".format(x, y))


if __name__ == '__main__':
    run()



Measured memory_bytes: 5652
S = input()
a = S[0]
b = S[1]
c = S[2]
d = S[3]

if a == b and c == d and a != c:
    print("Yes")
elif a == c and b == d and a != b:
    print("Yes")
elif a == d and c == b and a != b:
    print("Yes")
else:
    print("No")


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

int divisor_num(int n) {
    int count = 0;
    for (int i = 1; i <= n; i++) {
        if (n % i == 0) {
            count++;
        }
    }
    return count;
}

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

    int cnt = 0;
    for (int i = 1; i <= N; i+=2) {
        if (divisor_num(i) == 8) {
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long sum = 0;
		HashMap<Long, Integer> map = new HashMap<>();
		map.put(0L, 1);
		for (int i = 0; i < n ; i++) {
			sum += sc.nextLong();
			Integer x = map.get(sum);
			if (x == null) {
				x = 0;
			}
			map.put(sum, x+ 1);
		}
		long count = 0;
		for (int x : map.values()) {
			if (x >= 2) {
				count += (long)x * (long)(x - 1) / (long)2;
			}
		}
		System.out.print(count);
	}
			
}


Measured memory_bytes: 99888
#include<stdio.h>
int main()
{
	int n,k,x,y,sum;
	scanf("%d",&n);
	scanf("%d",&k);
	scanf("%d",&x);
	scanf("%d",&y);
	if(n > k)
	{
		sum = k * x + (n - k) * y;
		printf("%d\n",sum);
	}
	else
	{
		sum = n * x;
		printf("%d\n",sum);
	}
	return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    string s;
    cin >> s;
    rep(i, s.length()) {
        if ( s[i] == ',' ) cout << " ";
        else               cout << s[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int n, i, x = 0, max = 0;
  scanf("%d\n", &n);  //何回scanすればいいかを調べる
  char c;

  for (i = 0; i < n; i++) {
    scanf("%c", &c);
    if (c == 'D') {  //減らす
      x = x - 1;
    } else if (c == 'I') {
      x = x + 1;
      if (x > max) max = x;
    }
  }

  printf("%d\n", max);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstdio>
using namespace std;

#define int long long
#define INF 1e18

signed main() {
    vector<int> abc(3); cin >> abc[0] >> abc[1] >> abc[2];
    int k; cin >> k;

    sort(abc.begin(), abc.end());

    int ans = abc[0] + abc[1] + abc[2] * pow(2, k);

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,t;
  cin >> n >> t;
  vector<int> time(n);
  for(int i=0;i<n;i++){
    cin >> time.at(i);
  }
  int sum = 0;
  for(int i = 1;i < n;i++){
    int sa = time.at(i)-time.at(i-1);
    if(sa > t) sa = t;
    sum += sa;
  }
  cout << sum + t << endl;
}

    
    
  

Measured memory_bytes: 1024
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  n:Integer;
begin
  try
    { TODO -oUser -cConsole メイン : ここにコードを記述してください }
    Readln(n);

    Writeln(n*800 - n div 15 * 200);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
 
int main ()
{
    string s;
    cin >> s;

    int ans = 0;
    int cnt = 0;
    REP(i,s.size()) {
        if (s[i] == 'R') {
            cnt++;
        }
        if (s[i] == 'S' || i == s.size() - 1) {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(void){

    int N;
    string S, T;
    cin >> N;
    cin >> S >> T;

    for(int i=0; i<N; i++){
        cout << S[i] << T[i];
    }

    cout << endl;

    return 0;
}

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

int main(){
    long N;
    cin >> N;
    string N_binary = "";
    long N_mod, x;
    long N_defined = -1;
    long two_pow = 1;
    long minus_two_pow = 1;
    long index = 1;
    while (N != N_defined){
        two_pow *= 2;
        if (index == 1){
            if (N % 2 == 0){
                N_binary = "0" + N_binary;
                N_defined = 0;
            }else{
                N_binary = "1" + N_binary;
                N_defined = 1;
            }
        }else{
            minus_two_pow *= -2;
            N_mod = N % two_pow;
            x = (N_mod - N_defined) / minus_two_pow;
            //cout << "index: " << index << ",N_mod: " << N_mod << ",N_defined: " << N_defined << ",minus_two_pow: " << minus_two_pow << ",x: " << x << endl;
            if (x % 2 == 0){
                N_binary = "0" + N_binary;
                N_defined += 0;
            }else{
                N_binary = "1" + N_binary;
                N_defined += minus_two_pow;
            }
        }
        index++;
    }
    cout << N_binary << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)

char S[12];

int main() {

	scanf("%s", S);

	if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) printf("Bad\n");
	else printf("Good\n");

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	a := iScan()
	b := iScan()
	c := iScan()
	d := iScan()
	p := make([]int, n)
	q := make([]int, n)
	r := make([]int, n)
	s := make([]int, n)
	p[0] = a
	q[0] = a
	for i := 1; i < n; i++ {
		p[i] = p[i-1] + c
		q[i] = q[i-1] + d
	}
	r[n-1] = b
	s[n-1] = b
	for i := n - 2; i >= 0; i-- {
		r[i] = r[i+1] + c
		s[i] = s[i+1] + d
	}
	ans := "NO"
	for i := 0; i < n; i++ {
		if larger(p[i], r[i]) <= smaller(q[i], s[i]) {
			ans = "YES"
		}
	}
	fmt.Println(ans)
}


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

using namespace std;
const int N = 100010;
int n, m, par[N], sz[N], vis[N];

void make_set(int v) {
  par[v] = v;
  sz[v] = 1;
}

int find_set(int v) {
  if (v == par[v]) return v;
  return find_set(par[v]);
}

void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (sz[a] < sz[b]) swap(a, b);
    par[b] = a;
    sz[a] += sz[b];
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m; 
  for (int i = 1; i <= n; ++i) make_set(i);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    union_sets(u, v);
  }
  int cnt = 0;
  for (int i= 1; i <= n; ++i) {
    if (!vis[find_set(i)]) {
      cnt++;
      vis[find_set(i)] = 1;
    }
  }
  cout << cnt - 1 << '\n';
}

Measured memory_bytes: 4828
#include<stdio.h>
int main(void){
  int a,b;
  int d,r;
  double f;
  scanf("%d %d",&a,&b);
  if(a>=1 || b<=10*10*10*10*10*10*10*10*10){
  d=a/b;
  r=a%b;
  f=(double)a/(double)b;
  printf("%d %d %.5f\n",d,r,f);
  };
  return 0;
}

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

int main(void){
	int N;
	double D;
	cin >> N >> D;
	double X[N], Y[N];
	rep(i,N) cin >> X[i] >> Y[i];
	int ans = 0;
	rep(i,N) {
		double d2 = sqrt(X[i]*X[i] + Y[i]*Y[i]);
		if (d2 <= D) ans++;
	}
	cout << ans << endl;
return 0;
}


Measured memory_bytes: 6964
// AGC022
// B - GCD Sequence

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_A = 30000;
const int M = 8;

int N;

int main() {
    vector<int> pat;

    cin >> N;

    if (N == 3) {
        cout << "2 5 63" << endl;
        return 0;
    } else if (N % 2 == 0) {
        pat = {2, 4, 3, 9, 8, 10, 6, 12};
    } else {
        pat = {6, 2, 4, 3, 9, 8, 10, 12};
    }

    for (int i = 0; i < N; i++) {
        cout << pat[i % M] + i / M * 12;
        cout << (i == N - 1 ? '\n' : ' ');
    }

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
static char s[101], s2[201], p[101];
int main(void) {
    int i, j;
    scanf("%s%s", s, p);
    for (i = 0; s[i]; ++i)
        s2[i] = s[i];
    for (j = 0;; ++j, ++i) {
        s2[i] = s[j];
        if (!s[j]) break;
    }
    for (i = 0; s2[i]; ++i) {
        for (j = 0;; ++j) {
            if (!p[j]) {
                puts("Yes");
                return 0;
            }
            if (s2[i + j] != p[j]) break;
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 524
from collections import Counter
from itertools import product
s = list(input())
MOD = 10**9+7
c = Counter([0])
ds = list(range(10))
mods = list(range(13))

ten_power = 1
while s:
    char = s.pop()
    if char == '?':
        cand = ds
    else:
        cand = [int(char)]
    nc = Counter()
    for key, d in product(mods, cand):
        new_key = (key + d * ten_power) % 13
        nc[new_key] += c[key]
        nc[new_key] %= MOD
    c = nc
    ten_power *= 10
    ten_power %= 13

print(nc[5])

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

using namespace std;

int main(){
  int N, M, flg=0;
  cin >> N >> M;
  string A[N], B[N];
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  for (int i = 0; i < M; i++){
    cin >> B[i];
  }

  for (int i = 0; i < N - M + 1; i++){
    for (int j = 0; j < N - M + 1; j++){
      for (int k = 0; k < M; k++){
        if (A[i + k].substr(j, M) != B[k]) break;
        if (k == M - 1) flg = 1;
      }
    }
    if (flg == 1) break;
  }
  if (flg == 0) {
    printf("No\n");
  } else{
    printf("Yes\n");
  }
  
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

	static Main queue[];
	static int front = 0, rear = 0;
	static int h, w;
	static String s[];
	int x, y;
	
	public static boolean isempty() {
		return (front == rear);
	}
	
	public static int quesize() {
		if(front < rear)return rear - front;
		else return rear - front + queue.length;
	}
	
	public static void put(Main n) {
		int max = queue.length;
		if(quesize() == max - 1)return;
		rear = (rear + 1) % max;
		queue[rear] = n;
	}
	
	public static Main dequeue() {
		if(isempty())return new Main(-1, -1);
		front = (front + 1) % queue.length;
		return queue[front];
	}
	
	public Main(int x, int y) {
		this.x = x;
		this.y = y;
	}
	
	public boolean same(Main t) {
		return(x == t.x && y == t.y);
	}
	
	public void next(Main t) {
		x += t.x;
		y += t.y;
	}
	
	public boolean isinfield() {
		return (x >= 1 && x <= h && y >= 1 && y <= w);
	}
	
	public static int solve() {
		int memo[][] = new int[h + 1][w + 1];
		memo[1][1] = 1;
		Main move[] = {new Main(0, -1), new Main(0, 1), new Main(-1, 0), new Main(1, 0)};
		put(new Main(1, 1));
		Main goal = new Main(h, w);
		while(!isempty()) {
			Main cur = dequeue();
			if(cur.same(goal))return memo[cur.x][cur.y];
			for(int i = 0; i < 4; ++i) {
				Main next = new Main(cur.x, cur.y);
				next.next(move[i]);
				if(next.isinfield()) {
					char t = s[next.x].charAt(next.y - 1);
					if(t == '.') {
						if(memo[next.x][next.y] == 0) {
							put(next);
							memo[next.x][next.y] = memo[cur.x][cur.y] + 1;
						}
					}
				}
			}
		}
		return -1;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		h = sc.nextInt();
		w = sc.nextInt();
		s = new String[h + 1];
		queue = new Main[h * w + 1];
		int max = 0;
		for(int i = 0; i < h * w + 1; ++i)queue[i] = new Main(0, 0);
		for (int i = 1; i <= h; ++i) {
			s[i] = sc.next();
			for(int j = 0; j < w; ++j) {
				if(s[i].charAt(j) == '.')++max;
			}
		}
		sc.close();
		int ans = 0;
		ans = solve();
		if(ans != -1)ans = max - ans;
		System.out.println(ans);
	}

}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
using pii = pair<int,int>;
const int INF = 1e7 + 7;
int H , W , K , st_x , st_y , end_x , end_y;

int main()
{
   //freopen("killer_01.txt" , "r" , stdin);
   // freopen("killer_01_out.txt" , "w" , stdout);

    cin >> H >> W >> K ;
    cin >> st_x >> st_y >> end_x >> end_y ;
     --st_x , --st_y , --end_x , --end_y;
    vector<vector<char>> g (H , vector<char> (W));

    for(int i = 0 ; i < H ; i ++)
        for(int j = 0 ; j < W ; j++)
            cin >> g[i][j];

    vector<vector<int>> dist(H , vector<int> (W,INF));
    dist[st_x][st_y] = 0;
    queue<pii> q;
    vector<int> dir1 = {-1,1,0,0};
    vector<int> dir2 = {0,0,1,-1};
    q.push({st_x , st_y});


    while(!q.empty())
    {
        auto f = q.front() ; q.pop();
        int x = f.F , y = f.S , d = dist[x][y];
        if(x == end_x && y == end_y)
        {
            cout << d << endl;
            return 0;
        }
        for(int pos = 0 ; pos < 4 ; pos++)
            for(int i = 1 ; i <= K ; i++)
            {   
                int xx = x + i*dir1[pos] , yy = y + i*dir2[pos];
                if(xx < 0 || yy < 0 || xx >= H || yy >= W || dist[xx][yy] <= d || g[xx][yy] == '@') break;
                if(dist[xx][yy] > d + 1)
                {
                    dist[xx][yy] = d + 1;
                    q.push({xx,yy});
                }
            }
    }

    cout << -1 << endl;
    return 0;    



}

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

def sieve_of_eratosthenes(n):
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit < p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

prime = sieve_of_eratosthenes(10**5 + 1)

numlike2017 = [0 for i in range(10**5 + 1)]
for i in prime:
    if (i+1)//2 in prime:
        numlike2017[i] = 1

def cumulative_sum(collection):
    result = [collection.pop(0)]
    for item in collection:
        result.append(result[-1] + item)
    return result
cs2017 = cumulative_sum(numlike2017)

ans = []
for i in range(n):
    a, b = map(int, input().split())
    ans.append(cs2017[b] - cs2017[a-1])

for i in ans:
    print(i , flush=True)


Measured memory_bytes: 17692
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n = inp()
a = inpl()
ans = 1
if 0 in a:
    print(0)
    exit()
for i in a:
    ans *= i
    if ans > 10**18:
        print(-1)
        exit()
print(ans)


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) { cin >> v[i]; }

  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int now = i + 1;
    if (v[i] == now) {  // 入れ替える必要が
      swap(v[i], v[i + 1]);
      ans++;
    }
  }
  if (v[n-1] == n) ans++; // 最後の一回
  
  cout << ans << endl;
}


Measured memory_bytes: 640
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 
ll MAXN=100001;
ll spf[100001]; 
 
ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 

 
void solve()
{
	ll n ; 
	cin>>n ;
	
	cout<<((n-1)*n)/2<<endl;
}
 
int main() {
    // #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
    
    // ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    } 
    // cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] P = new int[N];
		int[] C = new int[N];
		
		for(int i=0; i<N; i++)
			P[i] = sc.nextInt()-1;
		for(int i=0; i<N; i++)
			C[i] = sc.nextInt();
		
		boolean[] visited = new boolean[N];
		
		long ans = Long.MIN_VALUE;
		for(int i=0; i<N; i++) {
			if(!visited[i]) {
				ArrayList<Integer> list = new ArrayList<>();
				int cur = i;
				while(!visited[cur]) {
//					list.add(cur);
					list.add(C[cur]);
					visited[cur] = true;
					cur = P[cur];
				}
				ans =max(ans, solve2(list, C, K));
			}
		}
		
		System.out.println(ans);
		sc.close();
	}
	
	static long solve(ArrayList<Integer> list, int[] C, int K) {
		int L = list.size();
		long[] score = new long[L+L+1];
		for(int i=0; i<L+L; i++) {
			score[i+1] = score[i] + C[list.get(i%L)];
		}
//		long[][] score = new long[L][L+1];
//		for(int i=0; i<L; i++) {
//			for(int j=0; j<L; j++) {
//				score[i][j+1] = score[i][j]+C[list.get((i+j)%L)];
//			}
//		}
		
		long ans = Long.MIN_VALUE;
		for(int i=0; i<L; i++) {
			for(int j=1; j<=((K-1)%L)+1; j++) {
//				ans = Math.max(ans, score[i][j]);
				ans = Math.max(ans, score[i+j] - score[i]);
			}
		}
//		if(score[0][L]>0) {
//			ans += score[0][L]*((K-1)/L);
//		}
		if(score[L]>0) {
			ans += score[L]*((K-1)/L);
		}
		
		return ans;
	}
	
    static long solve2(ArrayList<Integer> g, int[] C, int k) {
        int n = g.size();
        long[] arr = new long[n + n + 1];
        int idx = 1;
        for (int i : g) {
            arr[idx++] = i;
        }
 
        for (int i : g) {
            arr[idx++] = i;
        }
 
        long maxVal = Long.MIN_VALUE;
 
        for (int i = 1; i <= n + n; i++) {
            arr[i] += arr[i - 1];
        }
 
        long fullSum = arr[min(n, k)];
 
        long div = k / n;
        int rem = k % n;
 
        for (int i = 1; i <= n; i++) {
            int j = i + min(n, k) - 1;
            long sum = Long.MIN_VALUE;
            for(int p = i, cnt = 1; p <= j; p++, cnt++) {
                long psum = getSum(arr, i, p);
                sum = max(sum, psum);
                if(cnt <= rem) sum = max(sum, (div * fullSum) + psum);
                else if(div > 0) sum = max(sum, ((div - 1) * fullSum) + psum);
            }
 
            maxVal = max(maxVal, sum);
        }
        return maxVal;
    }
 
    static long getSum(long[] arr, int i, int j) {
        return arr[j] - arr[i - 1];
    }
 
    static long maxSubArraySum(long a[], int start, int end) {
        long maxSoFar = Long.MIN_VALUE, maxEndingHere = 0;
        for (int i = start; i <= end; i++) {
            maxEndingHere = maxEndingHere + a[i];
            if (maxSoFar < maxEndingHere)
                maxSoFar = maxEndingHere;
            if (maxEndingHere < 0)
                maxEndingHere = 0;
        }
        return maxSoFar;
    }

}


Measured memory_bytes: 40240
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int alice = 0;
  int bob = 0;
  cin >> N;
  vector<int>data(N);
  for(int i=0; i<N; i++){
   	cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  reverse(data.begin(), data.end());
  for(int i=0; i<N; i++){
    if(i % 2 == 0){
      alice = alice + data.at(i);
    }else{
      bob = bob + data.at(i);
    }
  }
  cout << alice - bob << endl;
}

Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    int r,g,b;
    cin >> r >> g >> b;
    if((10*g+b)%4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

int main(){
 
  int n,m,sum;
  sum =0;
  cin >> n >> m ;
  int a[m];
  
  for(int i=0;m>i;i++){
    
   cin >> a[i];
   sum+=a[i];
  }
  
  if(n<sum){
   
    cout << -1 <<endl;
    
  }
  
  else{
   
    cout << n-sum << endl;
    
  }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int a[105][105];
int main()
{
   int i, j, k, N;

   cin >> N;

   for (i = 0; i < 2; i++)
      for (j = 0; j < N; j++)
         cin >> a[i][j];

   a[1][0] += a[0][0];


   for (i = 1; i < N; i++) {
      a[0][i] += a[0][i - 1];
      a[1][i] += max(a[0][i], a[1][i - 1]);
   }

   cout << a[1][N - 1];


   return 0;
}


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

int main(){
  long long N,D;
  cin >> N >> D;
  vector<long long> X(N),Y(N);
  for (long long i = 0; i < N; i++){
    cin >> X.at(i) >> Y.at(i);
  }
  
  long long count = 0;
  for (long long i = 0; i < N; i++){
    if (X.at(i)*X.at(i)+Y.at(i)*Y.at(i)<=D*D){
      count++;
    }
  }
  
  cout << count;
}  

Measured memory_bytes: 6420
h, w = map(int, input().split())
s = [str(input()) for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            flag = False
            for di, dj in (-1, 0), (1, 0), (0, 1), (0, -1):
                ni, nj = i+di, j+dj
                if 0 <= ni < h and 0<= nj < w:
                    if s[ni][nj] == '#':
                        flag = True
            if not flag:
                print('No')
                exit()
else:
    print('Yes')


Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
const int MAXN=300000;
int n,k,ans[MAXN+5],panjang;
int main()
{
	scan(k,n);
	if(k==1)
	{
		int jumlah=(n+1)/2;			//ceil
		for(int i=1;i<=jumlah;i++)
			printf("%d%c",1,(i==jumlah)?'\n':' ');
	}
	else if((k&1)==0)
	{
		for(int i=1;i<=n;i++)
			printf("%d%c",(i==1)?(k>>1):k,(i==n)?'\n':' ');
	}
	else
	{
		panjang=n;
		for(int i=1;i<=n;i++)
			ans[i]=(k+1)/2;			//ceil
		
		int banyakkurang=n/2;
		while(banyakkurang--)
		{
			if(ans[panjang]==1)
			{
				panjang--;
			}
			else
			{
				ans[panjang]--;
				for(panjang++;panjang<=n;panjang++)
					ans[panjang]=k;
				panjang--;
			}
		}
		
		for(int i=1;i<=panjang;i++)
			printf("%d%c",ans[i],(i==panjang)?'\n':' ');
	}
}

Measured memory_bytes: 3456
n = int(input())
w = [input() for _ in range(n)]
flag = 0
if len(set(w)) == len(w):
    hoge = ''
    for i in range(n):
        if i == 0:
            hoge = w[i][len(w[i])-1]
        elif hoge == w[i][0]:
            hoge = w[i][len(w[i])-1]
        else:
            flag = 1
            break
    if flag == 1:
        print('No')
    else:
        print('Yes')
else:
    print('No')

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

int main(){
  int n;
  cin >> n;
  vector<int> a1(n);
  vector<int> a2(n);

  for (int i = 0; i < n; i++)
  {
    cin >> a1[i];
  }
  for (int i = 0; i < n; i++)
  {
    cin >> a2[i];
  }

  int maxa=0,cnt=0;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j <= i; j++)
    {
      cnt+=a1[j];   
    }
    for (int k = i; k < n; k++)
    {
      cnt+=a2[k];
    }
    maxa=max(maxa,cnt);
    cnt=0;
  }
  
  cout << maxa << endl;
  
}

Measured memory_bytes: 256
/*************************
__________________________
|                         |
|     Don't Hack Me!      |
|  Go Find Someone Else!  |
|_________________________|
        \_(O_O)_/
          |   |
          -----
          _| |_

*************************/

#include <bits/stdc++.h>
#include <iostream>


#define f first
#define s second
#define pb push_back
#define all(a) a.begin(), a.end()
#define mp make_pair
#define MAXN 1000005
using namespace std;

typedef long long ll;

const int maxn=1e97;
int main()
{
       ll n, k;
    cin >> n >> k;
    vector<long long> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<long long> dp(n, maxn);
    dp[0] = 0;
    for (ll i = 0; i < n; i++)
    {
        for (ll j = i + 1; j <= i + k; j++)
        {
            if (j < n)
            {
                dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
            }
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 4832
#C - Coloring Colorfully
S = list(input())
a = []
b = []
aans = 0
bans = 0

for i in range(len(S)):
    if i%2 == 0:
        a.append('0')
        b.append('1')
    else:
        a.append('1')
        b.append('0')
        
for i in range(len(S)):
    if S[i] != a[i]:
        aans += 1
    if S[i] != b[i]:
        bans += 1
if aans >= bans:
    print(bans)
else:
    print(aans)


Measured memory_bytes: 5512