akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    // 回答をここに書く
    val s = next()
    val r = s.map { if (it == '+') 1 else -1 }.sum()
    println(r)
}

// 入力取得
fun next() = br.readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

// 約数のList
fun divisor(value : Long) : List<Long> {
    val max = Math.sqrt(value.toDouble()).toLong()
    return (1..max)
        .filter { value % it == 0L }
        .map { listOf(it, value / it) }
        .flatten()
        .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from : Long, to : Long = from) : List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j ->  i % j != 0L }
    }
}

// 素因数分解
fun decom(value : Long) : List<Long>{
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a : Long, b : Long) : Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base : String, a : String, b : String) : String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 29352
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())

print(a[k-1])

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

int a[100010], p[100010];
int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0;i < n;i++){
		scanf("%d", &a[i]);
		if(a[i]-1 >= 0)p[a[i]-1]++;
		p[a[i]]++;p[a[i]+1]++;
	}
	int ans = 0;
	for(int i = 0;i < 100010;i++){
		ans = max(ans, p[i]);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1024
S = list(map(int, input()))
start0 = [0, 1]*(len(S)//2+1)
start1 = [1, 0]*(len(S)//2+1)
ans = [0, 0]
for i, j, k in zip(S, start0, start1):
    if(i != j):
        ans[0] += 1
    if(i != k):
        ans[1] += 1
print(min(ans))

Measured memory_bytes: 5536
import java.util.*;

public class Main {
    static long MOD = 1000000007;
    static long inv2 = 500000004;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] array = new long[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextLong();
        }
        
        // ans: 数列の全ペア(i,j)の積の和
        // 言い換え:
        // ab ac ad bc bd cd
        // (a+b+c+d)^2 = a^2+...d^2 + 2(ab ac ad ... cd)
        // ans = ((a+b+c+d)^2 - (a^2+...d^2))/2 (inv2を掛ける)
        
        // parta: 総和の2乗
        long parta = 0;
        for (int i = 0; i < n; i++) {
            parta += array[i];
            parta %= MOD;
        }
        parta = (parta * parta) % MOD;
        // System.out.println(parta);
        
        // partb: 各要素の2乗の和
        long partb = 0;
        for (int i = 0; i < n; i++) {
            partb += (array[i] * array[i]) % MOD;
            partb %= MOD;
        }
        // System.out.println(partb);
        
        long ans = parta - partb;
        if (ans < 0) ans += MOD;
        ans %= MOD;
        ans *= inv2;
        ans %= MOD;
        System.out.println(ans);
    }
    
    public static long modpow(long num, long n) {
        // ex. 3^10
        // 3^10 = 3^(0b1010)
        // = 3^8が1個 * 3^4が0個 * 3^2が1個 * 3^1が0個
        // (次の桁の値は(前の桁)^2になる)
        
        long res = 1;
        long digit = num;
        
        while (n > 0) {
            long lsb = n & 1;
            if (lsb == 1) {
                res *= digit;
                res %= MOD;
            }
            
            digit = digit * digit;
            digit %= MOD;
            n = n >> 1;
        }
        
        return res;
    }
}


Measured memory_bytes: 60748
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<set>
#include<vector>
#include<iomanip>
#include<numeric>
using namespace std;

int main(){
  int N,L;cin>>N>>L;
  vector<string> s(N);
  for(int i=0;i<N;i++)cin>>s.at(i);
  sort(s.begin(),s.end());
  for(int i=0;i<N;i++)cout<<s.at(i);
  cout<<endl;
  

  return 0;
}


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

bool sameCheck (int a, int b) {
  if (a == b) return true;
  else return false;
}

int main() {
  int A, B;
  cin >> A >> B;
  
  int count = 0;
  for (int i=A; i<=B; ++i) {
    int j = i;
    int d[5];
    for (int k=0; j>0; ++k) {
      d[k] = j % 10;
      j = j / 10;
    }
    if (sameCheck(d[0], d[4]) && sameCheck(d[1], d[3])) ++count;
  }
  
  cout << count << endl;
}
  
  

Measured memory_bytes: 256
from collections import Counter
from itertools import combinations

N = int(input())
initials = [input()[0] for _ in range(N)]
initials = [initial for initial in initials if initial in {'M', 'A', 'R', 'C', 'H'}]
counter = Counter(initials)
joined = ''.join(set(initials))

print(sum([counter[c1] * counter[c2] * counter[c3] for c1, c2, c3 in combinations(joined, r=3)]))


Measured memory_bytes: 4984
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;

 
int main() {
    ll n,m,s;
    cin >> n >> m >> s;
    vector<vector<pair<ll,pp>>> e(n,vector<pair<ll,pp>>(0));
    vector<pp> r(n);
    rep(i,m){
        ll f,g,h,ff;
        cin >> f >> g >> h >> ff;
        e[f-1].push_back(mk(g-1,mk(h,ff)));
        e[g-1].push_back(mk(f-1,mk(h,ff)));
    }
    rep(i,n){
        ll f,g;
        cin >> f >> g;
        r[i]=mk(f,g);
    }
    vector<vector<ll>> a(n,vector<ll>(10000,INF));
    if (s>=10000) s=9999;
    a[0][s]=0;
    queue<pp> q;
    q.push(mk(0,s));
    while(!q.empty()){
        ll f=q.front().first,g=q.front().second;
        q.pop();
        ll u=g+r[f].first;
        if (u>=10000) u=9999;
        if (a[f][u]>a[f][g]+r[f].second){
            a[f][u]=a[f][g]+r[f].second;
            q.push(mk(f,u));
        } 
        rep(i,e[f].size()){
            if (g-e[f][i].second.first<0) continue;
            if (a[e[f][i].first][g-e[f][i].second.first]>a[f][g]+e[f][i].second.second){
                a[e[f][i].first][g-e[f][i].second.first]=a[f][g]+e[f][i].second.second;
                q.push(mk(e[f][i].first,g-e[f][i].second.first));
            }
        }
    } 
    rep(i,n-1){
        ll ans=INF;
        rep(j,10000){
            ans=min(ans,a[i+1][j]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 8248
s=list(input())
t=list(input())
xs=len(s)
xt=len(t)
count=1000
for i in range(xs-xt+1):
    temp=0
    for j in range(xt):
        if s[i+j]!=t[j]:
            temp+=1
    count=min(temp,count)
print(count)

Measured memory_bytes: 9124
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;



int main(){
    int N;
    cin >> N;
    LL mi=LINF,rmi=LINF,mx=-1,rmx=-1;
    vector<P> v;
    for (int i = 0; i < N; i++) {
        LL x,y;
        cin >> x >> y;
        if(y>x) swap(x,y);
        mi=min(mi,y);
        rmi=min(rmi,x);
        mx=max(mx,x);
        rmx=max(rmx,y);
        v.pb({x,y});
    }
    LL ans=(mx-rmi)*(rmx-mi);
    sort(RALL(v));
    LL t=mx-mi;
    LL limi=-1;
    for (int i = 0; i < N-1; i++) {
        if(v[i].fs<limi) break;
        rmi=min(rmi,v[i].sc);
        if(v[i].fs>v[i+1].fs){
            mx=max({v[i].sc,v[i+1].fs,limi});
        }
        ans=min(ans,t*(mx-rmi));
        limi=max(limi,v[i].sc);
    }
    cout << ans << endl;
    return 0;
}



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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vll>;
df data(n, vll(m));
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
*/


/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/range/algorithm.hpp> // boost::sort(arr)
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
using boost::algorithm::join; // string s = join(arr, "");
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

int main() {
  int n;
  cin >> n;
  int max_div = 0;
  int ans = 1;
  for (int i = 1; i <= n; ++i) {
    int div = 0;
    int test = i;
    while (test % 2 == 0) {
      ++div;
      test /= 2;
    }
    if (div > max_div) {
      max_div = div;
      ans = i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;
using System;
class Program
{
    static void Main()
    {
        int a = int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());

        int current = 1;
        for (int i = 0; i < a; i++){
            if (current < b)
            {
                current *= 2;
            }else{
                current += b;
            }

        }
        Console.WriteLine(current.ToString());
    }
}

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

#define f first
#define s second
#define all(x) x.begin(),x.end()
#define pb push_back
#define ll long long

using namespace std;

int main()
{
    string s;
    cin >> s;
    int n=s.size();
    if(n&1){
        printf("No\n");
        return 0;
    }
    bool ok=1;
    for(int i=0;i<n;i+=2)
        if(s[i]!='h'||s[i+1]!='i')
            ok=0;
    printf(ok?"Yes":"No");
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if (s[n - 1] == 's') {
    cout << s + "es" << endl;
  } else {
    cout << s + 's' << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
using System;

class Maximum{
    static void Main(string[] args){
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ');
        var aArray = new int[n];
        var min = (int)Math.Pow(10, 9);;
        var max = 0;
        for(int i=0; i<n; i++){
            aArray[i] = int.Parse(a[i]);
            if(aArray[i]>max){
                max = aArray[i];
            }
            if(aArray[i]<min){
                min = aArray[i];
            }
        }

        Console.WriteLine(max-min);
    }
}

Measured memory_bytes: 13140
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int num = sc.nextInt();
    int change = 0;
    
    while (num > 1000) {
      num -= 1000;
    }
    
    change = 1000 - num;
    System.out.println(change);
  }
}

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

#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;

bool is_done[51];

lli gcd(lli a, lli b) {
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    lli r;
      r = a % b;

  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main() {
    lli n;
    cin >> n;
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }
    vector<P> xy;
    REP(i, 0, n) {
        lli xi, yi;
        cin >> xi >> yi;
        xy.push_back(P(xi, yi));
    }
    sort(xy.begin(), xy.end());
    //REP(i, 0, xy.size()) {
    //    cout << "x: " << xy[i].first << ", y: " << xy[i].second << endl;
    //}
    lli ans = LLONG_MAX;
    REP(i, 0, n) {
        REP(j, 0, n) {
            if (i == j)
                continue;

            // この(p, q)の組み合わせでのコストを出す。
            lli p = xy[j].first - xy[i].first;
            lli q = xy[j].second - xy[i].second;

            // 集合を作る
            set<P> s;
            REP(i, 0, n) {
                s.insert(P(xy[i].first, xy[i].second));
            }

            // 一個取り出す => それに (p, q) を足してあったら消す、みたいにやっていく
            lli cur_cost = 0;
            REP(i, 0, n) {
                lli x = xy[i].first;
                lli y = xy[i].second;
                P orig = P(x, y);
                if (s.find(orig) == s.end()) {
                    continue;
                }
                s.erase(orig);
                cur_cost++;
                while (true) {
                    x += p;
                    y += q;
                    P target = P(x, y);

                    if (s.find(target) == s.end()) {
                        break;
                    }

                    s.erase(target);
                }
            }

            ans = min(ans, cur_cost);
        }
    }
    cout << ans << endl;
}


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

int main(int argc, char *argv[])
{
  int n, m, l;
  cin >> n >> m >> l;
  long long int a[101][101] = {}, b[101][101] = {}, c[101][101] = {};
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++){
      cin >> a[i][j];
    }
  }

  for(int i = 0; i < m; i++) {
    for(int j = 0; j < l; j++){
      cin >> b[i][j];
    }
  }

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < l; j++) {
      for(int k = 0; k < m; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < l; j++){
      if(j) cout << " ";
      cout << c[i][j];
    }
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3304
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int h1 = scanner.nextInt();
        int m1 = scanner.nextInt();
        int h2 = scanner.nextInt();
        int m2 = scanner.nextInt();
        int minutes = scanner.nextInt();

        int ms1 = h1 * 60 + m1;
        int ms2 = h2 * 60 + m2;

        int result = ms2 - ms1 - minutes;
        System.out.println(result);
    }
}

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

int main(){
  int n,m;
  cin>>n>>m;
  string a[n];
  string b[m];
  rep(i,0,n){
    cin>>a[i];
  }
  rep(i,0,m){
    cin>>b[i];
  }
  bool p=false;
  rep(i,0,n-m+1){
    rep(j,0,n-m+1){
      bool q=true;
      rep(k,0,m){
        rep(l,0,m){
          if(a[i+k][j+l]!=b[k][l]){
            q=false;
          }
        }
      }
      if(q) p=true;
    }
  }
  if(p) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 1000000007;
const ll longinf = 1LL << 60;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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




ll n, cnt;
ll l[100000];

int main() {

	cin >> n;
	rep(i, n)cin >> l[i];

	if (n >= 3){
		rep(i, n){
			REP(j, i + 1, n){
				REP(k, j + 1, n){
					ll ma = max(max(l[i], l[j]), l[k]);
					if ((l[i] != l[j]) && (l[i] != l[k]) && (l[j] != l[k]) && (ma * 2 < l[i] + l[j] + l[k])){
						cnt++;
					}
				}
			}
		}
	}

	cout << cnt << endl;

	return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()


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

  string S;
  cin>>S;
  string code="CODEFESTIVAL2016";
  int ans=0;
  for(int i=0;i<S.size();i++){
    if(S[i]!=code[i])ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000
void countingsort(short *,short *,int);
int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);
  for(i=0;i<n;i++)scanf("%d",&A[i+1]);
  
  /* your code */
  countingsort(A,B,n);
  for(i=1;i<=n;i++){
    if(i>1)printf(" ");
    printf("%d",B[i]);
    
  }printf("\n");

  return 0;
}

void countingsort(short A[],short B[],int n){
 int C[VMAX+1];
 int i,j;
  for(i=0;i<=VMAX;i++)C[i]=0;

  /*count the number of i*/
  for(j=1;j<=n;j++)C[A[j]]++;

  /*count the number of figure less than i+1*/
  for(i=1;i<=VMAX;i++)C[i]=C[i]+C[i-1];

  for(j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

}



Measured memory_bytes: 9588
#include<stdio.h>
int main(void){

int H,W,i,j,k;

while(1){
	scanf("%d %d",&H,&W);
	if(H == 0 && W == 0)break;
	
	for(i=1;i<=W;i++){
		printf("%c",'#');
	}
	printf("\n");
	
	for(j=1;j<=H-2;j++){
		printf("%c",'#');
		
		for(k=1;k<=W-2;k++){
			printf("%c",'.');
		}
		
		printf("%c\n",'#');
	}
	for(i=1;i<=W;i++){
		printf("%c",'#');
	}
	printf("\n\n");
}
return 0;
}


Measured memory_bytes: 2044
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

size_t N;
string S;
char headc[5] = {'M', 'A', 'R', 'C', 'H'};
vector<ll> head_num(5, 0);

void mysort(string s)
{
    for (size_t i = 0; i < 5; i++) {
        if (s.front() == headc[i]) {
            head_num[i]++;
            return;
        }
    }
    return;
}

int main()
{
    cin >> N;
    S.resize(N);
    for (size_t i = 0; i < N; i++) {
        cin >> S;
        mysort(S);
    }

    sort(head_num.begin(), head_num.end());
    ll times = 1;
    ll sump = 0;

    if (head_num[0] > 0) {
        for (size_t i = 0; i < 4; i++) {
            for (size_t j = i + 1; j < 5; j++) {
                for (size_t k = 0; k < 5; k++) {
                    if (k != i && k != j) {
                        times *= head_num[k];
                    }
                }
                sump += times;
                times = 1;
            }
        }
        cout << sump << endl;
    } else if (head_num[1] > 0) {
        for (size_t i = 1; i < 5; i++) {
            for (size_t k = 1; k < 5; k++) {
                if (k != i) {
                    times *= head_num[k];
                }
            }
            sump += times;
            times = 1;
        }
        cout << sump << endl;
    } else {
        for (size_t k = 2; k < 5; k++) {
            times *= head_num[k];
        }
        cout << times << endl;
    }

    return 0;
}

Measured memory_bytes: 384
n, l, t = map(int,input().split())
ants = [tuple(map(int,input().split())) for _ in range(n)]
y = [(x + t * ((m + 1) % 3 - 1)) % l for x, m in ants]
fy = y[0]
y.sort()
firx, firm = ants[0]
c = 0
for x, m in ants:
  if firm != m:
    if firm == 1:
      c += max(-1, 2 * t - x + firx) // l + 1
    else:
      c += max(-1, 2 * t - l + x - firx) // l + 1
iy = (c if firm == 1 else -c) % n
if firm == 1:
  for i in range(n-1, -1, -1):
    if y[i] == fy:
      pi = (i - iy) % n
      break
else:
  for i in range(n):
    if y[i] == fy:
      pi = (i - iy) % n
      break
al = y[pi:] + y[:pi]
print(*al, sep='\n')

Measured memory_bytes: 20800
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    if (10 % p == 0) {
        ll ans = 0;
        rep(r, n) {
            if ((s[r] - '0') % p == 0) {
                ans += r + 1;
            }
        }
        cout << ans << endl;
        return 0;
    }

    vector<int> d(n + 1);
    int ten = 1;
    for (int i = n - 1; i >= 0; --i) {
        int a = (s[i] - '0') * ten % p;
        d[i] += (d[i+1] + a) % p;
        ten *= 10;
        ten %= p;
    }

    vector<int> cnt(p);
    ll ans = 0;
    // iを左端の桁としたときに、右側に選べる物が何個あるかをカウントしながら追加している
    for (int i = n; i >= 0; --i) {
        ans += cnt[d[i]];
        cnt[d[i]]++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1428
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<vc> vcc;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 7;
vector<vii> adj;
vi color;
void dfs(int ind,int parent){
    for(auto item: adj[ind]){
        if(item.F==parent) continue;
        if(item.S==1) color[item.F]=!color[ind];
        else color[item.F]=color[ind];
        dfs(item.F,ind);
    }  
}
void solve(){
    int n;
    cin>>n;
    adj = vector<vii>(n+1,vii());
    color = vi(n+1);
    color[1]=0;
    for(int i = 0; i < n-1; i++){
        int a,b,c; cin>>a>>b>>c;
        adj[a].pb({b,c%2});
        adj[b].pb({a,c%2});
    }
    dfs(1,-1);
    for(int i = 1; i <= n; i++) cout<<color[i]<<endl;    
}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

Measured memory_bytes: 8192
import Foundation
// 第一引数には約数を列挙したい自然数を渡す
func print_divisors(n:Int)->[Int]{
    // 戻り値となる配列の初期化
    var divisors:[Int] = []
    // ループを回すのは√nまでで十分
    for i in 1...Int(sqrt(Double(n))){
        // 割り切れるならiはnの約数
        if n % i == 0{
            divisors.append(i)
            // i != n / i なら i^2 != n
            if i != n / i{
                divisors.append(n/i)
            }
        }
    }
    // 配列をソートする
    divisors.sort{ $0 < $1 }
    // divisorsを返す
    return divisors
}

// 標準入力の受け取り
let n = Int(readLine()!)!

// 約数列挙
let check = print_divisors(n:n)

// 答えとなる変数ansの初期化 (とりあえずめっちゃでかい値入れておく)
var ans = 100000000000000

// 各約数についてループを回す
for i in check{
    
    // ループは √n までで十分
    if i > Int(sqrt(Double(n))){
        break
    }
    
    // より小さい値をansに代入
    ans = min(ans,i+n/i-2)
}

// 答えを返す
print(ans)

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

int main()
{
  int n, y;
  cin >> n >> y;
  
  bool flag = true;
  for (int i=0; i<=n; i++) {
    if (flag) {
		for (int j=0; j<=n-i; j++) {
    	  int x = y;
   	   x -= 10000 * i;
   	   x -= 5000 * j;
   	   if (x == 1000 * (n-i-j)) {
    	    cout << i << " " << j << " " << n-i-j << endl;
    	    flag = false;
     	   break;
    	  }
        }
    }
  }
  if (flag) cout << "-1 -1 -1" << endl;
}
        

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MN = 100;
const int MW = 10000;

int dp[MN+1][MW+1];
vector<int> v,w;

int rec(int n,int u){
    if(dp[n][u] != -1){
        return dp[n][u];
    }

    if(n == v.size()){
        return 0;
    }

    if(w[n] > u){
        return dp[n][u] = rec(n+1,u);
    }else{
        return dp[n][u] = max(rec(n+1,u),rec(n,u-w[n])+v[n]);
    }
}

/* int main(){
    int N,W;

    cin >> N >> W;

    for(int i=0; i<N; i++){
        int s,t;
        cin >> s >> t;
        v.push_back(s);
        w.push_back(t);
    }

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

    cout << dp[N][W] << endl;
} */

int main(){
    int N,W;

    cin >> N >> W;

    for(int i=0; i<N; i++){
        int s,t;
        cin >> s >> t;
        v.push_back(s);
        w.push_back(t);
    }

    memset(dp,-1,sizeof(dp));

    cout << rec(0,W) << endl;
}

Measured memory_bytes: 5632
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    if((a<1)||(9<a)){
      System.out.println(-1);
      return;
    }else if(b<1||9<b){
      System.out.println(-1);
      return;
    }
    
    System.out.println(a*b);
  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cctype>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < (n) ; ++i )
int main(){
  int n,dp[8][1001],g,m;
  while(cin >> n , n){
    int a[n],b[n];
    fill_n(dp[0],8008,0);
    dp[0][0] = 1;
    rep(i,n) cin >> a[i] >> b[i];
    for(int i = 0 ; i < n ; i++ ){
      for(int j = 0 ; j < 1001 ; j++ ){
        for(int k = 0 ; k <= b[i] ; k++){
          if( j + a[i] * k > 1000) break;
          dp[i+1][j + a[i] * k] += dp[i][j];
        }
      }
    }
    cin >> g;
    while(g--){
      cin >> m;
      cout << dp[n][m] << endl;
    }
  }
}

Measured memory_bytes: 3120
import sys
from sys import stdin
n,m,x,y = [int(x) for x in stdin.readline().rstrip().split()]
xs = [int(x) for x in stdin.readline().rstrip().split()]
ys = [int(x) for x in stdin.readline().rstrip().split()]
for i in range(-100, 101):
    if x < i <= y and max(xs) < i <= min(ys):
        print('No War')
        sys.exit()
print('War')

Measured memory_bytes: 3064
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	fsum := 0
	for i := 1; i <= n; i++ {
		if (i%3 != 0) && (i%5 != 0) {
			fsum += i
		}
	}

	fmt.Println(fsum)
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1756
R=range
l=[[[0 for i in R(10)]for j in R(3)]for s in R(4)]
for i in R(int(input())):b,f,r,v=map(int,input().split());l[b-1][f-1][r-1]+=v
for i in R(4):
 for k in l[i]:print("",*k)
 if i!=3:print("#"*20)

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n,x; cin >> n >> x;
    ll res = 1,sum = 0;
    rep(i,n){
        ll l; cin >> l;
        sum = sum + l;
        if(sum <= x)res++;
    }
    out(res);
}


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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;



int main() {
    int N; cin >> N;
    vvll a(N, vll(3));
    rep(i, N) cin >> a[i][0] >> a[i][1] >> a[i][2];

    vector<vll> dp(N + 1, vll(3, 0));
    for (int i = 1; i <= N; i++) {
        rep(j, 3) {
            rep(k, 3) {
                if (k == j) continue;
                chmax(dp[i][j], dp[i - 1][k] + a[i - 1][k]);
            }
        }
    }

    ll ans = 0;
    rep(k, 3) chmax(ans, dp[N][k]);

    cout << ans << endl;
}


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

int main()
{int n;
cin>> n;
vector<int> dp(n+1);
rep(i,n+1)
{
 if(i==0||i==1)
 {dp.at(i)=1; continue;}
 dp.at(i)=dp.at(i-2)+dp.at(i-1);
}

cout<<dp.at(n)<<endl;
    return 0;
}


Measured memory_bytes: 3080
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main(){

	int N;
	scanf("%d",&N);

	if(N == 1){
		printf("1\n");
		return 0;
	}

	int max_diff = 0;

	int near_bottom = 0,near_top = 0;

	int pre,tmp;
	scanf("%d",&pre);

	int value = 0;

	for(int i = 1; i < N; i++){
		scanf("%d",&tmp);

		if(tmp == pre){
			//Do nothing
		}else if(tmp > pre){

			value++;
			near_top = value;

			max_diff = max(max_diff,value-near_bottom);

		}else{
			value--;
			near_bottom = value;

			max_diff = max(max_diff,near_top-value);
		}
		pre = tmp;
	}

	printf("%d\n",max_diff+1);

	return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  int h;
  rep(i, n) {
    cin >> h;
    if (h >= k) ans++;
  }

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

Measured memory_bytes: 256
N = int(input())
ans = [0]*(N+1)

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            val = (x**2 + y**2 + z**2 + x*y + y*z +z*x)
            if  val <= N:
                ans[val] += 1

for i in range(1, N+1):
    print(ans[i])
                 





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

using namespace std;

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

    vector<int> a(n);
    for (auto &x:a) cin >> x;
    sort(a.begin(), a.end());

    int ans1 = a[n - 1];
    int ans2 = a[0];
    double mid = a[n - 1] / 2.0;
    for (auto x:a) {
        if (abs(x - mid) < abs(ans2 - mid)) {
            ans2 = x;
        }
    }

    cout << ans1 << " " << ans2 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll A, B; cin >> A >> B;
  RNG(i, 1, 10001) {
    if ((ll)(i*0.08) == A && (ll)(i*0.1) == B) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
bool echeck(ll a) { return a % 2 == 0 ? 1 : 0; }
ll comb(ll n, ll m){
  ll tmp = 1;
  for(int i = n; i >= n - m + 1; i--){
    tmp *= i;
  }
  ll temp = 1;
  for(int i = 1; i <= m; i++){
    temp *= i;
  }
  return tmp / temp;
}
bool check(int i,string s,string t){
  int tsize = t.size();
  string tmp = s.substr(i,tsize);
  bool r = true;
  rep(i,tsize){
    if(tmp[i] != t[i] && tmp[i] != '?')r = false;
  }
  return r;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  string s,t;
  cin >> s >> t;
  string ans = s;
  bool can = false;
  int x;
  for(int i = s.size() - t.size() + 1; i > -1; i--){
    if(check(i,s,t)){
      can = true;
      x = i;
      break;
    }
  }
  if(!(can)){
    cout << "UNRESTORABLE" << endl;
  }
  else{
    int j = 0;
    REP(i,x,x + t.size()){
      if(s[i] != t[j]) s[i] = t[j];
      j++;
    }
    rep(i,s.size()){
      if(s[i] == '?')cout << 'a';
      else cout << s[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if( a == b + c || b == c +a || c == a+b){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }        
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<numeric>
#include<limits.h>
#include<utility>
#include<cstdlib>
#include<bitset>
#define LP(i,n) for(int i=0;i<n;i++)
#define LPIN(n,a) for(int i=0;i<n;i++)cin >> a[i]
using namespace std;

int main(){
    int n,d;
    cin >> n >>d;
    int ans = (n / (d*2 +1));
    if(n % (d*2 +1) != 0)ans+=1;
    cout << ans;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int x = 0;
  int ma = 0;
  for (int i = 0; i < N; i ++) {
    char c;
    cin >> c;
    if (c == 'I') x ++;
    else x --;
    ma = max(ma, x);
  }
  cout << ma << endl;
}

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

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

int main(void){

    int x;
    cin >> x;
    if(x == 0) cout << 1 << endl;
    else cout << 0 << endl;     

    return 0;
}

Measured memory_bytes: 3540
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int now;
string s;

int number(){
  int res=0;
  while('0'<=s[now] && s[now]<='9')
    res*=10,res+=s[now++]-'0';
  return res/2+1;
}

int factor(){
  
  if(s[now]=='['){
    vector<int>v;
    while(s[now]=='['){
      now++;
      v.push_back(factor());
      now++;
    }
    sort(v.begin(),v.end());
    int res=0;
    for(int i=0;i<v.size()/2+1;i++)res+=v[i];
    return res;
  }
  return number();
}

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

  while(n--){
    now=0;
    cin >> s;
    cout << factor() << endl;
  }

  return 0;
}

Measured memory_bytes: 1276
N = int(input())
task = [tuple(map(int, input().split())) for i in range(N)]
task.sort(key=lambda x:x[1])
task_sum = 0
for a, b in task:
    task_sum += a
    if task_sum > b:
        print("No")
        break
else:
    print("Yes")

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

int main() {
  int s1;
  char s2;
  int s3;
  cin>>s1>>s2>>s3;
  if(s2=='+'){
    cout<<s1+s3<<endl;
  }
  else if(s2=='-'){
    cout<<s1-s3<<endl;
  }
}
  


Measured memory_bytes: 256
from math import ceil, floor
 
a, b = [int(c) for c in input().split(" ")]
A = ceil(a / 0.08)
B = ceil(b/ 0.1)
 
if (A < B):
  if (floor(B * 0.08) == a):
    print(B)
  else:
    print(-1)
elif (B < A):
  if (floor(A*0.1) == b):
    print(A)
  else:
    print(-1)
else:
  print(A);

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

struct Matrix{
    Int val[50][50];
    Matrix(){
        for(int i = 0;i < 50;i++){
            for(int j = 0;j < 50;j++){
                val[i][j] = 0;
            }
        }
    }
};

Matrix I;

Matrix operator*(Matrix a, Matrix b){
    Matrix c;
    for(int i = 0;i < 50;i++){
        for(int j = 0;j < 50;j++){
            for(int k = 0;k < 50;k++){
                c.val[i][j] += a.val[i][k] * b.val[k][j] %MOD;
                c.val[i][j] %= MOD;
            }
        }
    }
    return c;
}

Int n, k;

Matrix matrix_power(Matrix a, Int b){
    if(b == 0)return I;
    Matrix res = matrix_power(a, b/2);
    res = res * res;
    if(b % 2 == 1)res = res * a;
    return res;
}

int main(){
    for(int i = 0;i < 50;i++)I.val[i][i] = 1;

    Matrix A;
    cin >> n >> k;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            cin >> A.val[i][j];
        }
    }

    Matrix A_k = matrix_power(A, k);
    Int ans = 0;
    for(int i =0;i < n;i++){
        for(int j = 0;j < n;j++){
            ans += A_k.val[i][j];
            ans %= MOD;
        }
    }

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

Measured memory_bytes: 9600
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a==5&&b==5&&c==7||a==7&&b==5&&c==5||a==5&&b==7&&c==5){
        cout << "YES";
    }else{
        cout << "NO";
    }
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
if N==1:
    print(1)
    exit()

B=[A[i]-A[i-1] for i in range(1,N)]
ans=0
flag=False
for i in range(N-1):
    if B[i]!=0:
        first=B[i]
        flag=True
    if flag:
        break
for i in range(N-1):
    if first*B[i]>=0:
        pass
    else:
        ans+=1
        j=i+1
        while j<=N-2:
            if B[j]!=0:
                first=B[j]
                break
            else:
                j+=1

print(ans+1)

Measured memory_bytes: 20196
N = int(input())

A_list = list(map(int, input().split()))

for i in range(N):
    if A_list[i] % 2 == 0:
        if A_list[i] % 3 == 0 or A_list[i] % 5 == 0:
            continue
        else:
            print("DENIED")
            exit()

if i == N-1:
    print("APPROVED")


Measured memory_bytes: 9172
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

diff :: [Int] -> [Int] -> [Int]
diff a b = map (\(p, q) -> p - q) $ zip a b

calc :: [[Int]] -> String
calc (txy : []) = "Yes"
calc (txy : txy' : txys)
  | result == True = calc (txy' : txys)
  | otherwise = "No"
  where
    [t, x, y] = diff txy' txy
    d = t - (abs x + abs y)
    result =
      if d < 0 || odd d
        then False
        else True

main = do
  n <- getInt
  txys <- getIntNList n
  let txys' = [0, 0, 0] : txys
  putStrLn $ calc txys'


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

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

  map<ll, int> m;
  for (int i = 0; i < n; i++) {
    if (m.count(a[i]) == 0) m[a[i]] = 0;
    m[a[i]]++;
  }
  int ans = 0;
  for (auto e : m) {
    if (e.first < e.second) {
      ans += e.second - e.first;
    } else if (e.first > e.second) {
      ans += e.second;
    }
  }
  cout << ans << endl;
}


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

#define io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pii pair<ll, ll>
#define piii pair<ll, pair<ll, ll>>
#define debug(x) cout<<#x<<" = "<<x<<endl

using namespace std;
const int N = 100005;
ll t, n, m, k, q, a, b, x, y, ans, arr[N];
bool vis[N], valid;
ll mod = 998244353;
string s;

int main() {
    io;
    t = 1;
//    cin >> t;
    while (t--) {
        cin >> x >> n;
        set<ll> st;
        for (int i = 0; i < n; ++i) {
            cin >> y;
            st.insert(y);
        }
        ans = INT_MAX, k = 1e9;
        for (int i = -200; i <= 200; ++i) {
            if (st.count(i))
                continue;
            if (llabs(x - i) < k)
                k = llabs(x - i), ans = i;
            else if (llabs(x - i) == k)
                ans = min(ans, 1ll * i);
        }
        cout << ans << endl;
    }
    return 0;
}
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);


Measured memory_bytes: 3652
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

#include <iomanip>

int n, m;
vi dp, va;
const int cost[]{ 0,2,5,5,4,5,6,3,7,6 };
const int minf = -100;

void init()
{
	cin >> n >> m;
	dp.resize(n + 1, minf);
	dp[0] = 0;

	va.resize(m);
	REP(i, m) cin >> va[i];
	sort(ALL(va), greater<>());
}

int main()
{
	init();

	REP(i, n)
	{
		if (dp[i] == minf)
			continue;
		for (int a : va)
		{
			if (i + cost[a] <= n)
				chmax(dp[i + cost[a]], dp[i] + 1);
		}
	}

	//REPC(i, n)
	//	cout << setw(5) << dp[i];
	//cout << endl;

	string res = "";
	int i = n;

	while (i > 0)
	{
		for (int a : va)
		{
			if (i - cost[a] >= 0)
				if (dp[i - cost[a]] == dp[i] - 1)
				{
					res.PB(a + '0');
					i -= cost[a];
					break;
				}
		}
	}

	cout << res << endl;
}


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

int main(int argc, char const *argv[])
{
	ll x, k, d, n;
	cin >> x >> k >> d;

	x = abs(x);
	n = x/d;

	if(n >= k)
		cout << abs(x - k*d);
	else
	{ 
		if((x - n*d) <= abs(x - (n+1)*d))
		{
			if(n%2 == k%2)
				cout << x-n*d;
			else
				cout << abs(x-(n+1)*d);
		}
		else
		{
			if(n%2 == k%2)
				cout << x-n*d;
			else
				cout << abs(x-(n+1)*d);
		}

	}
	return 0;
}

Measured memory_bytes: 3596