akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a,b,c;
        int ck=0;
        
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        
        for(;a<=b;a++){
            if(c%a == 0){
                ck++;
            }
        }
        System.out.println(ck);
        
        sc.close();
    }
}


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

const int maxn = 1e5 + 10;
typedef pair<int, int> Seg;
Seg seg[maxn], sseg[maxn];

struct cmpL {
	bool operator () (const Seg&a, const Seg&b) {
		return a.first == b.first ? a.second < b.second : a.first < b.first;
	}
};

struct cmpR {
	bool operator () (const Seg&a, const Seg&b) {
		return a.second == b.second ? a.first < b.first : a.second < b.second;
	}
};

Seg operator & (const Seg&a, const Seg&b) {
	return make_pair(max(a.first, b.first), min(a.second, b.second));
}
	
int len(const Seg &a) {
	//if (a.second < a.first) return -INT_MAX / 2;
	return max(0, a.second - a.first + 1);
}


int main() {
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++) 
		scanf("%d%d", &seg[i].first, &seg[i].second);
	sort(seg + 1, seg + 1 + n, cmpR());
	sseg[n] = seg[n];
	for (int i = n - 1; i >= 1; i--)
		sseg[i] = sseg[i + 1] & seg[i];
	Seg seg1 = seg[1]; 
	int ans = 0;
	for (int i = 2; i <= n; i++) {
		Seg tmp1 = seg1, tmp2 = seg[i];
		if (i != n) {
			if (tmp1.first < tmp2.first)
				tmp2 = tmp2 & sseg[i + 1];
			else 
				tmp1 = tmp1 & sseg[i + 1];
		}
		ans = max(ans, len(tmp1) + len(tmp2));
		
		seg1 = seg1 & seg[i];
	}
	seg1 = seg[1];
	for (int i = 2; i <= n; i++) {
		Seg tmp1 = seg1, tmp2 = seg[i];
		if (i != n) {
			if (tmp1.first > tmp2.first)
				tmp2 = tmp2 & sseg[i + 1];
			else 
				tmp1 = tmp1 & sseg[i + 1];
		}
		ans = max(ans, len(tmp1) + len(tmp2));
		
		seg1 = seg1 & seg[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<long long> v;
  for(int i=1;i<=n;i++){
    long long a;
    cin>>a;
    v.push_back(a);
  }
  sort(v.begin(),v.end());
  int flag=0;
  for(int i=0;i<=n-2;i++){
    if(v[i]==v[i+1]){
      flag=1;
      cout<<"NO"<<endl;
      break;
    }
  }
  if(flag==0){
    cout<<"YES"<<endl;
  }
  return 0;
}

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

int main(){
  string s="",command;
  cin>>command;
  for(int i=0;i<command.size();i++){
    switch(command[i]){
      case '0':
        s+='0';
        break;
      case '1':
        s+='1';
        break;
      case 'B':
        if(s.size()!=0){
          s.erase(s.size()-1,1);
        }
        break;
    }
  }
  cout<<s<<endl;
}


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

int main() {
	int n;cin>>n;
	int ans=0;
	for(int i=1;i<=n;i+=2){
		int count=0;
		for(int j=1;j<=i;j++){
			if(i%j==0)count++;
		}
		if(count==8)ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
mod = 10 ** 9 + 7

SIZE = 2 * 10 ** 6 + 5
fact = [0] * SIZE
inv = [0] * SIZE
finv = [0] * SIZE
fact[0], fact[1] = 1, 1
inv[1] = 1
finv[0], finv[1] = 1, 1
for i in range(2, SIZE):
    fact[i] = fact[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod


def nCr(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    return fact[n] * (finv[r] * finv[n - r] % mod) % mod


k = int(input())
S = input()
s_length = len(S)
full_length = len(S) + k
ans = 0
for i in range(k+1):
    add = pow(26, i, mod) * pow(25, k-i, mod) * nCr(full_length-i-1, s_length-1) % mod
    ans = (ans + add) % mod

print(ans)



Measured memory_bytes: 132840
import std.stdio, std.string, std.conv, std.bigint, std.typecons, std.algorithm, std.array, std.math, std.range, std.functional;
 
void main() {
    auto N = readln.chomp.to!int;
    sort(N.iota.map!(i => readln.chomp.to!ulong).array).group.filter!(g => g[1] % 2 == 1).array.length.writeln;
}


Measured memory_bytes: 4988
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
l.sort()

count = 0
price = 0

for i in range(len(l)):
    if count + l[i][1] <= m:
        price += l[i][0] * l[i][1]
        count += l[i][1]
    elif count < m:
        price += (m - count) * l[i][0]
        break
print(price)

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

int dp[100005];
int main(){
    int n,k,i,j;
    cin>>n>>k;
    int a[n+1];

    for(i=0;i<=k;i++){
        dp[i]=-1;
    }

    for(i=1;i<=n;i++){
        cin>>a[i];
        dp[a[i]]=1;
    }

    for(i=0;i<a[1];i++) dp[i]=0;

    for(i=a[1]+1;i<=k;i++){
        if(dp[i]!=-1) continue;
        dp[i]=0;
        for(j=1;j<=n;j++){
            if((i-a[j])>0){
                if(!dp[i-a[j]]){
                    dp[i]=1;
                    break;
                }
            }
        }
    }

//    for(i=1;i<=k;i++) cout<<dp[i]<<" ";cout<<endl;

    if(dp[k]){
        cout<<"First\n";
    }else{
        cout<<"Second\n";
    }
}


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

int main() {
    int n, sum=0;
    cin >> n;
    vector<int> v(n);
    for (int i=0; i<n; i++)
        cin >> v[i];
    for (int i=1; i<n-1; i++)
        if ((v[i] <= v[i-1] && v[i] >= v[i+1]) || (v[i] >= v[i-1] && v[i] <= v[i+1]))
            sum++;
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	int a, b; cin >> a >> b;
	if (a + b >= 10) cout << "error" << endl;
	else cout << a + b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;
int main(void){
   int n;
   cin >> n;

   int x[n],y[n];
   for(int i = 0;i < n;i ++) cin >> x[i];
   for(int i = 0;i < n;i ++) cin >> y[i];

   double D_p1 = 0;
   for(int i = 0;i < n;i ++){
       D_p1 += fabs(x[i] - y[i]);
   }

   double D_p2 = 0;
   for(int i = 0;i < n;i ++){
       D_p2 += pow(x[i] - y[i],2);
   }
   D_p2 = sqrt(D_p2);

   double D_p3 = 0;
   for(int i = 0;i < n;i ++){
       D_p3 += pow(fabs(x[i] - y[i]),3);
   }
   D_p3 = pow(D_p3,1.0/3.0);

   double D_p_inf = 0;
   for(int i = 0;i < n;i ++){
       if(fabs(x[i] - y[i]) > D_p_inf) D_p_inf = fabs(x[i] - y[i]);
   }

   cout << fixed << D_p1 << endl;
   cout << fixed << D_p2 << endl;
   cout << fixed << D_p3 << endl;
   cout << fixed << D_p_inf << endl;

}


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

int M,N;
int d[100001]={};
typedef pair<int,int> P;

int main() {
	vector<int> vec;
	queue<P> que;

	cin>>N;
	int R=1;
	int d1,d2;
	int a=0;
	cin>>d1;
	for(int i=1;i<N;++i){
		d2=d1;
		cin>>d1;
		if(a==0){
			if(d1>d2){
				a=1;
			}else if(d1<d2){
				a=-1;
			}
		}else{
			if(d1>d2&&a<0){
				a=0;
				++R;
			}else if(d1<d2&&a>0){
				a=0;
				++R;
			}
		}
	}

	cout << R<< endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	string a, b, c;
	cin >> a >> b >> c;
	a[0] -= 32;
	b[0] -= 32;
	c[0] -= 32;
	string ans;
	ans += a[0]; ans += b[0]; ans += c[0];
	print(ans);






	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
ans=0
for i in range(k,n+2):
    a=0.5*i*(i-1)
    b=0.5*n*(n+1)-0.5*(n-i)*(n-i+1)
    ans+=int(b-a+1)


print(ans%(10**9+7))

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

int main(){
    int n,m; cin>>n>>m;
    vector<vector<int>> vec(m);
    for(int i=0;i<m;i++){
        int k; cin>>k;
        vec[i].resize(k);
        for(int j=0;j<k;j++){
            cin>>vec[i][j];
            vec[i][j]--;
        }
    }
    vector<int> p(m);
    for(int i=0;i<m;i++) cin>>p[i];

    int ans=0;
    for(int i=0;i<(1<<n);i++){
        bool ok=true;
        for(int j=0;j<m;j++){
            int c=0;
            for(auto t:vec[j]){
                if((i>>t)&1) c++;
            }
            c%=2;
            if(c!=p[j]) ok=false;
        }
        if(ok) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int m = scanner.nextInt();
        int f = scanner.nextInt();
        int b = scanner.nextInt();
        if( m > b ){
            System.out.println("0");
        } else if (m + f >= b) {
            System.out.println(b - m);
        } else {
            System.out.println("NA");
        }
    }
}



Measured memory_bytes: 26312
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int sum = 0;
        int[] arr = new int[n];
        int ans = 1;
        for(int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
            sum += arr[i];
        }
        ArrayList<Integer> factors = new ArrayList<>();
        factors.add(1);factors.add(sum);
        for(int i = 2; i*i<=sum; i++) {
            if (sum % i == 0) {
                if (sum/i != i) factors.add(sum/i);
                factors.add(i);
            }
        }
        for(int i =0; i < factors.size(); i++) {
            int curfactor = factors.get(i);
            TreeMap<Integer, Integer> mapping = new TreeMap<>();
            long cost = 0;
            long used = 0;
            for(int j = 0; j < n; j++) {
                int cur = arr[j] % curfactor;
                if (!mapping.containsKey(cur)) mapping.put(cur, 0);
                mapping.put(cur, mapping.get(cur) + 1);
                cost += curfactor - cur;
            }
            while(!mapping.isEmpty()) {
                int minKey = mapping.firstKey();
                mapping.put(minKey, mapping.get(minKey)-1);
                if (mapping.get(minKey) == 0) mapping.remove(minKey);
                used += minKey;
                cost -= curfactor - minKey;
                //this is guaranteed to trigger since the total mod adds to zero
                if (cost == used && used <= k) ans = Math.max(ans, curfactor);
            }
        }
        out.println(ans);
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

int main(){
	long long int n;
	long long int a,b;
	long long int s=0;
	long long int sum=0;
	long long int blue=0;
	cin>>n>>a>>b;
	s=n/(a+b);
	if(a>0){
		blue=a*s+min(a,n-s*(a+b));
	}
	if(b==0) blue=n;
	
	

	
	cout<<blue;
}
	

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int V = sc.nextInt();
        int B = sc.nextInt();
        int W = sc.nextInt();
        int T = sc.nextInt();

        if (V==W) {
            if (A==B) System.out.println("YES");
            else System.out.println("NO");
        } else {
            if ((long)(V-W)*T>=Math.abs(A-B)) System.out.println("YES");
            else System.out.println("NO");
        }
    }
}

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

string st1, st2;
int pref1[100100], pref2[100100];
int Q,a,b,c,d;

int main(){
  cin >> st1 >> st2;
  for (int i=0;i<st1.size();++i){
    pref1[i+1] = (st1[i] == 'A');
    pref1[i+1] += pref1[i];
  }
  for (int i=0;i<st2.size();++i){
    pref2[i+1] = (st2[i] == 'A');
    pref2[i+1] += pref2[i];
  }
  cin >> Q;
  while(Q--){
    cin >>a >>b >> c >> d;
    int t = (pref1[b] - pref1[a-1])%3;
    int t2 = (pref2[d] - pref2[c-1])%3;
    int tb = (b - a + 4 - t)%3;
    int t2b = (d - c + 4 - t2)%3;
    int td = (t + 3 - tb)%3;
    int t2d = (t2 + 3 - t2b)%3;

    if (td == t2d)cout<<"YES\n";
    else cout << "NO\n";
  }
}

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

using namespace std;
using ll = long long;

int main() {
    int N = 0, K;
    cin >> N >> K;
    vector<int> A(N,0);
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    int ans = 1000000010;
    for(int i = 0; i < N - K + 1; i++) {
        ans = min(ans, A.at(i) - A.at(i + K - 1));
        //cout << A.at(i) << ':' << A.at(i + K - 1) << endl;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <limits>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int waru = 1000000007;
ll powz(ll x,ll n){
    ll res =1;
    while(n>0){
        if(n & 1){
            res =res*x%waru;
        }
        x = x*x%waru;
        n >>=1;
    }
    return res;
}


int main(){
    int m,n;
    cin >> m >> n;
  
    cout << powz(m,n)<< endl;
}




Measured memory_bytes: 3116
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/14/20 20:53:44
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int h,w,k; cin>>h>>w>>k;
  int a,b,c,d; cin>>a>>b>>c>>d; a--; b--; c--; d--;
  vector<string> grid(h);
  for (int i = 0; i < h; i++) {
    cin>>grid[i];
  }

  constexpr int INF = 1e9;
  struct Cost {
    int x,c,k;
    Cost operator+(const Cost& r) const {
      auto xx = x+r.x;
      auto cc = c+r.c;
      if (cc >= k) {
        xx++;
        cc-=k;
      }
      return {xx,cc,k};
    }
    bool operator<(const Cost& r) const {
      return x!=r.x ? x<r.x : c<r.c;
    }
    bool operator==(const Cost& r) const {
      return x==r.x and c==r.c;
    }
    bool operator<=(const Cost& r) const {
      return *this < r or *this == r;
    }
    bool operator>(const Cost& r) const {
      return r<(*this);
    }
    Cost ceil() const {
      return {x+(c>0), 0, k};
    }
  };
  const Cost DC = {INF, 0, k};
  vector<vector<array<Cost,4>>> dist(h, vector<array<Cost,4>>(w, {DC,DC,DC,DC}));
  struct Pos {
    int x,y,d;
    Cost c;
    bool operator>(const Pos& rhs) const {
      return rhs.c < c;
    }
  };
  priority_queue<Pos, vector<Pos>, greater<>> qs;
  for (int i = 0; i < 4; i++) {
    dist[a][b][i] = {0,0,k};
    qs.push({a,b,i, {0,0,k}});
  }
  constexpr int dir[4][2] = {
    {-1,0},
    {1,0},
    {0,-1},
    {0,1}
  };
  const Cost mcost{0, 1, k};
  while (not qs.empty()) {
    const auto [x,y,d,c] = qs.top(); qs.pop();
    if (dist[x][y][d] < c) continue;
    auto fx = x+dir[d][0];
    auto fy = y+dir[d][1];
    if (fx >= 0 and fx < h and fy >= 0 and fy < w and
        dist[fx][fy][d] > c+mcost and
        grid[fx][fy] == '.') {
      dist[fx][fy][d] = c+mcost;
      qs.push({fx,fy,d, c+mcost});
    }
    auto cc = c.ceil();
    for (int i = 0; i < 4; i++) {
      if (i == d) continue;
      if (dist[x][y][i] <= cc) continue;
      dist[x][y][i] = cc;
      qs.push({x,y,i,cc});
    }
  }
  auto ans = min_element(dist[c][d].begin(), dist[c][d].end())->ceil();
  cout << (ans==DC ? -1 : ans.x) << endl;

  return 0;
}


Measured memory_bytes: 97980
n = int(input())
p = list(map(float,input().split()))
if n == 1:
    print(p[0])
    exit()
dp = [[0 for j in range(i+1)] for i in range(n+1)]
dp[1][0] = 1-p[0]
dp[1][1] = p[0]
ans = 0
for i in range(2,n+1):
    for j in range(i+1):
        if i-1 >= j and j >= 1:
            dp[i][j] = p[i-1]*dp[i-1][j-1] + (1-p[i-1])*dp[i-1][j]
        elif i-1>=j:
            dp[i][j] = (1-p[i-1])*dp[i-1][j]
        elif j>=1:
            dp[i][j] = p[i-1]*dp[i-1][j-1]

        if i <= 2*j and i == n:
            ans += dp[i][j]


print(ans)

Measured memory_bytes: 151304
package main

import (
	"fmt"
)

var N int
var S string
var a int
var b int
var c int
var C int

func main() {
	fmt.Scan(&N)

	for n := 0; n < N; n++ {
		fmt.Scan(&S)
		var A bool
		for _, s := range S {
			if A {
				if s == 'B' {
					C++
				}
				A = false
			}
			if 'A' == s {
				A = true
			}
		}
		if S[0] == 'B' && S[len(S)-1] == 'A' {
			c++
		} else if S[0] == 'B' {
			b++
		} else if S[len(S)-1] == 'A' {
			a++
		}
	}

	if c > 1 {
		C += c - 1
		c = 1
	}
	m := min(a, b, c)
	C += 2 * m
	if a-m > 0 {
		if b-m > 0 {
			C += min(a-m, b-m)
		}
		if c-m > 0 {
			C += min(a-m, c-m)
		}
	} else if b-m > 0 {
		if c-m > 0 {
			C += min(b-m, c-m)
		}
	}
	fmt.Println(C)
}

func min(X ...int) int {
	m := X[0]
	for _, x := range X {
		if m > x {
			m = x
		}
	}
	return m
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<cassert>
#include<climits>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
 
using namespace std;
 
// Library - cycoro - begin -7:26
 
enum FACE {TOP,BOTTOM,FRONT,BACK,LEFT,RIGHT};
 
template<class T>
class dice{
public:
  dice(){
    //id[FRONT] = 0; id[RIGHT] = 1; id[TOP] = 2;
    //id[BOTTOM] = 3; id[LEFT] = 4; id[BACK] = 5;
    id[TOP] = 0; id[FRONT] = 1; id[LEFT] = 2;
    id[RIGHT] = 3; id[BACK] = 4; id[BOTTOM] = 5;
  }
  T& operator[] (FACE f){ return var[id[f]]; }
  const T& operator[] (FACE f)const { return var[id[f]];}
  bool operator == (const dice<T> &b)const{
    const dice<T> &a = *this;
    return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] && 
      a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
      a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
  }
 
  void roll_x() { roll(TOP,BACK,BOTTOM,FRONT); }
  void roll_y() { roll(TOP,LEFT,BOTTOM,RIGHT); }
  void roll_z() { roll(FRONT,RIGHT,BACK,LEFT); }
 
  vector<dice> all_rolls(){
  vector<dice> ret;
  for(int k=0;k<6;(k&1?roll_y():roll_x()),++k)
    for(int i=0;i<4;roll_z(),++i)
      ret.push_back(*this);
  return ret;
  }
 
  bool equivalent_to(const dice& di){
    for(int k=0;k<6;(k&1?roll_y():roll_x()),++k)
      for(int i=0;i<4;roll_z(),++i)
    if(*this == di)return true;
    return false;
  }
 
private:
  void roll(FACE a,FACE b,FACE c,FACE d){
    T tmp = id[a];
    id[a] = id[b]; id[b] = id[c];
    id[c] = id[d]; id[d] = tmp;
  }
  T var[6];
  int id[6];
};
 
FACE face[] = {FRONT,RIGHT,TOP,BOTTOM,LEFT,BACK};
 
// Library - cycoro - end 07:34
 
int n,mincost;
vector<dice<int> > ALL[4];

void dfs(int cur,vector<dice<int> >&tmp){
  if(cur >= n){
    int cost = 0;
    //int counter[6];
    map<int,int> counter;
    rep(fc,6){
      counter.clear();
      //rep(i,6)counter[i] = 0;
      int mex = 0;
      rep(i,n){
    counter[tmp[i][face[fc]]]++;
    mex = max(mex,counter[tmp[i][face[fc]]]);   
      }
      cost += (n - mex);
      assert(n-mex >= 0);
    }
    mincost = min(cost,mincost);
    return;
  }
 
  rep(i,ALL[cur].size()){
    tmp[cur] = ALL[cur][i];
    dfs(cur+1,tmp);
  }
 
}
 
int main(){
 
  while(cin >> n,n){
    int idx = 0;
    mincost= IINF;
    map<string,int> getIndex;
    vector<dice<int> > dices(n);
    rep(i,n){
      rep(j,6){
    string color;
    cin >> color;
    if(getIndex.find(color) == getIndex.end())getIndex[color] = idx++;
    int index = getIndex[color];
    dices[i][face[j]] = index; 
      }
    }
 
    rep(i,n)ALL[i] = dices[i].all_rolls();
    vector<dice<int> > tmp(n);
 
    dfs(0,tmp);
 
 
    cout << mincost << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <random>
#include <unordered_set>
//#include <set>
#include <queue>
using namespace std;
typedef long long ll;


int main(){
	int N;
	cin >> N;
	vector<int> c(N-1),s(N-1),f(N-1);
	for(int i=0;i<N-1;i++)cin >> c[i] >> s[i] >> f[i];

	for(int i=0;i<N;i++){
		int now=0;
		for(int j=i;j<N-1;j++){
			if(now<=s[j]){
				now = s[j]+c[j];
			}else{
				now = (now-s[j]+f[j]-1)/f[j] * f[j] + s[j] + c[j];
			}
		}
		cout << now << endl;
	}


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()


void solve(){
 ll n,m;
  cin >> n >> m;
 vvll G(n);
 vll deg(n,0);
rep(i,0,n+m-1){
 ll u,v;
  cin >> u >> v;
  --u;
  --v;
  G[u].eb(v);
  ++deg[v];
}

queue<ll> que;
rep(i,0,n) if(!deg[i]) que.push(i);
vll ans(n,0);
while(!que.empty()){
 ll v=que.front();
    que.pop();
for(auto nv:G[v]){
  deg[nv]--;
 if(!deg[nv]) {
  ans[nv]=v+1;
   que.push(nv);
 
 }
}
}

for(auto x:ans) cout << x << endl;  
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  


Measured memory_bytes: 7936
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
using namespace std;

int main(){
    string x,y;
    cin >> x >> y;
    if ( x > y ) cout << '>' << endl;
    else if ( x == y ) cout << '=' << endl;
    else cout << '<' << endl;
}

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

const int mod = 1e9 + 7;

int main()
{
	string S;
	cin >> S;
	vector<int> dp(13);
	dp[0] = 1;
	for (auto c : S) {
		vector<int> tmp(13);
		for (int i = 0; i < 13; i++) {
			(tmp[i * 10 % 13] += dp[i]) %= mod;
		}
		dp.assign(13, 0);
		if (c == '?') {
			for (int d = 0; d < 10; d++) {
				for (int i = 0; i < 13; i++) {
					(dp[(i + d) % 13] += tmp[i]) %= mod;
				}
			}
		}
		else {
			for (int i = 0; i < 13; i++) {
				(dp[(i + c - '0') % 13] += tmp[i]) %= mod;
			}
		}
	}
	cout << dp[5] << endl;
	return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll a[1234],ans=0ll;
vector<ll> v[65];

int main(void){
	int n,m=0,c,k,i,j,t=62;
	a[0] = 0ll;
	cin >> n;
	cin >> k;
	for(i=0; i<n; ++i){
		cin >> a[i+1];
		a[i+1] += a[i];
	}
	for(i=0; i<n; ++i){
		for(j=i; j<n; ++j){
			v[t].push_back(a[j+1]-a[i]);
			++m;
		}
	}
	for(i=60; i>=0; --i){
		c = 0;
		for(j=0; j<m; ++j){
			if(v[t][j]&(1ll<<i)){
				++c;
			}
		}
		if(c>=k){
			ans += (1ll<<i);
			for(j=0; j<m; ++j){
				if(v[t][j]&(1ll<<i)){
					v[t-1].push_back(v[t][j]);
				}
			}
			--t;
			m = v[t].l_ength();
		}
	}
	cout << ans << endl;
	return 0;
}


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

int s[30];
int n;

int main() {
  
  while(1) {
    cin >> n;
    if(!n)break;
    
    s[0] = 1;
    s[1] = 2;
    s[2] = 4;
    
    for(int i=3;i<n;i++) {
      s[i] = s[i-1]+s[i-2]+s[i-3];
    }
    int r = s[n-1]/10;
    r += s[n-1]%10?1:0;
    r = (r-1)/365 + 1;
    cout << r << endl;
    
  }
  return 0;
}

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

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

int main() {
  int n, a, b;
  cin >> n >> a >>b;
  
  int ans = 0;
  ans = min(a * n, b);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
s=list(str(input()))
t=list(str(input()))
s.sort()

t.sort(reverse=True)
#print(s,t)

for i in range(min(len(s),len(t))):
   # print(s[i],t[i])
    if s[i]<t[i]:
        print("Yes")
        exit()
    elif s[i]>t[i]:
        print("No")
        exit()
if len(s)<len(t):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " [" << x.fi << " " << x.se << "]"<<endl;
#define debug_v(x) {cerr << #x << " "; for (auto ioi : x) cerr << ioi << " "; cerr << endl;}
#define debug_vp(x) {cerr << #x << " "; for (auto ioi : x) cerr << '[' << ioi.fi << " " << ioi.se << ']'; cerr << endl;}
#define debug_v_v(x) {cerr << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cerr << ioi2 << " "; cerr << '\n';} cerr << "*/" << #x << endl;}
#define gen_clock(x) ll x = clock(); cerr << "Clock " << #x << " created" << endl;
#define check_clock(x) cerr << "Time spent in " << #x << ": " << (double)(clock() - x)/CLOCKS_PER_SEC << endl; x = clock();
#define reset_clock(x) x = clock()
 
const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
 
void solve()
{
	ll n;
	cin>>n;
	vector <char>b;
	while(n>0)
	{
	if(n%26)
	{b.pb(char('a'-1+(n%26)));
	n-=(n%26);
	n/=26;
	}
	else
	{b.pb('z');
	n-=26;
	n/=26;
	}
	}
	for(ll i=b.size()-1;i>=0;i--)
	cout<<b[i];
	
}
 
int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


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

using namespace std;

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

#define st first
#define nd second

const int MAXN = 1e6 + 5, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18, MOD = 1e15 + 37;
const ld PI = acos(-1);

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(13) << fixed;

    //////////////////////////////////////////
    //////////////////////////////////////////

    string s, t;
    cin >> s >> t;
    int res = 0;
    for (int i = 0; i < s.size(); ++i) {
        res += s[i] != t[i];
    }
    cout << res << "\n";
}


Measured memory_bytes: 3796
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define mst(a,b) memset((a),(b),sizeof(a))
#define PII pair<int,int>
using namespace std;
template<class T>inline void read(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
const int maxn=100050;
int n,in[maxn],res;
map<PII,int> co;
int head[maxn],num;
PII ans[maxn];
struct node{
	int v,nex;
}e[maxn<<1];
void add(int u,int v)
{
	e[++num].nex=head[u];
	e[num].v=v;
	head[u]=num;
}
void dfs(int u,int fa,int pre)
{
	int c=1;
	if(c==pre) c++;
	for(int i=head[u];i;i=e[i].nex)
	{
		int v=e[i].v;
		if(v==fa) continue;
		co[make_pair(u,v)]=c;
		res=max(res,c);
		dfs(v,u,c);
		c++;
		if(c==pre) c++;
	}
}
int main()
{
	cin>>n;
	for(int i=1;i<=n-1;i++)
	{
		int x,y;
		read(x),read(y);
		if(x>y) swap(x,y);
		ans[i]=make_pair(x,y);
		add(x,y),add(y,x);
	}
	dfs(1,0,0);
	cout<<res<<endl;
	for(int i=1;i<=n-1;i++) cout<<co[ans[i]]<<endl;
	return 0;
}


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

using ll = long long;
const int INF = 1e9+100;

int diff(string a, string b){
	int n = a.size();
	int res = 0;
	for (int i = 0; i < n; i++){
		if (a[i] != b[i]){
			res++;
		}
	}
	return res;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s, t;
	cin>>s>>t;
	int ans = INF;
	int ss = s.size(), ts = t.size();
	for (int i = 0; i <= ss-ts; i++){
		ans = min(ans, diff(s.substr(i, ts), t));
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    const ll mod=1e9+7;
    int n;
    cin>>n;
    vector<int>a(n),b(n);
    rep(i,n)cin>>a[i];
    ll ans=1;
    b[0]=3;
    rep(i,n){
        ans*=b[a[i]];
        ans%=mod;
        b[a[i]]--; b[a[i]+1]++;
    }
    cout<<ans%mod<<endl;
}


Measured memory_bytes: 1024
import numpy as np
N = int(input())
h = np.array([int(x) for x in input().split()])

def count_num(z):
    prev = 0
    c = 0
    for i in range(len(z)):
        if prev <= 0 and z[i] > 0:
            c += 1
        prev = z[i]
    return c

count = 0
for i in range(100):
    count += count_num(h)
    h = h - 1
    if np.sum(h > 0) == 0:
        break

print(count)

Measured memory_bytes: 12496
// https://atcoder.jp/contests/abc063/tasks/abc063_b

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string s;
    cin >> s;

    vector<bool> used(26);

    for (int i = 0; i < s.size(); i++)
    {
        int j = s[i] - 'a';
        if (used[j])
        {
            cout << "no" << endl;
            return 0;
        }
        used[j] = true;
    }
    cout << "yes" << endl;
    return 0;
}


Measured memory_bytes: 3504
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>

using namespace std;

typedef long long int ll;
typedef long int li;

int main(void){
    ll ans = 0;
    ll n,k;
    cin >> n >> k;
    ll b = (n+1)/2;
    if(b>=k)cout << "YES" << endl;
    else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
## A
K = int(input())
A, B = map(int, input().split())
rt = 'NG'
if A == B:
    if A%K == 0:
        rt = 'OK'
else:
    for i in range(A,B+1):
        if i%K == 0:
            rt = 'OK'
            break
print(rt)

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005

int main(){
    LL n;
    scanf("%lld",&n);
    LL tot=n*(n+1)/2;
    LL sum=0;
    LL a[100005];
    for(int i = 0;i<n;i++)
        scanf("%lld",&a[i]),sum+=a[i];
    if(sum%tot!=0){
        printf("NO\n");
        return 0;
    }
    LL ti=sum/tot;
    LL cnt=0;
    for(int i = 0;i<n;i++){
        LL x=a[(i+1)%n]-a[i];
        LL sub=ti-x;
        if(sub%n!=0||sub<0){
            printf("NO\n");
            return 0;
        }

        cnt+=sub/n;
    }
    if(cnt==ti){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }
}

Measured memory_bytes: 1024
from numpy import *
P=10**9+7
N=int(input())
C=array([input().split() for _ in range(N)],int8)
def r(A):
  if(A==0).all():return 0
  i=A[:,0].nonzero()[0]
  if len(i) == 0:return r(A[:,1:])
  t=A[i[0]].copy();A[i[0]]=A[0];A[0]=t
  A[1:]^= A[1:,0][:,None]*A[0][None,:]
  return 1+r(A[1:,1:])
r=r(C)
p=ones(N+1,int64)
for n in range(1,N+1):p[n]=p[n-1]*2%P
d=zeros((N+1,N+1,N+1),int64);d[:,0,0]=1
for M in range(1,N+1):
  d[:,M,:M]+=d[:,M-1,:M]*p[:M]%P
  d[:,M,1:M+1]+=d[:,M-1,0:M]*(p[:,None]-p[None,0:M])%P
  d[:,M,:]%=P
print(sum(d[N,N,n]*d[N,n,r]%P*pow(2,N*(N-n),P)%P for n in range(r,N+1))%P*pow(int(d[N,N,r]),P-2,P)%P)

Measured memory_bytes: 227888
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

typedef struct{
  char mark;
  int value;
}Card;

Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(Card A[], int n, int left, int mid, int right){
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(i = 0; i < n1; i++) L[i] = A[left + i];
  for(i = 0; i < n2; i++) R[i] = A[mid + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k = left; k < right; k++){
    if(L[i].value <= R[j].value){
      A[k] = L[i++];
    }else{
      A[k] = R[j++];
    }
  }
}

void mergeSort(Card A[], int n, int left, int right){
  int mid;
  if(left + 1 < right){
    mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int partition(Card A[], int n, int p, int r){
  int i, j;
  Card t, x;
  x = A[r];
  i = p - 1;
  for(j = p; j < r; j++){
    if(A[j].value <= x.value){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i + 1];
  A[i + 1] = A[r];
  A[r] = t;
  return i + 1;
}

void quickSort(Card A[], int n, int p, int r){
  int q;
  if(p < r){
    q = partition(A, n, p, r);
    quickSort(A, n, p, q - 1);
    quickSort(A, n, q + 1, r);
  }
}

int main(){
  int n, i, v;
  Card A[MAX], B[MAX];
  char S[10];
  int st = 1;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%s %d", S, &v);
    A[i].mark = B[i].mark = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, n, 0, n);
  quickSort(B, n, 0, n - 1);

  for(i = 0; i < n; i++){
    if(A[i].mark != B[i].mark) st = 0;
  }

  if(st == 1) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 0; i < n; i++){
    printf("%c %d\n", B[i].mark, B[i].value);
  }
  return 0;
}
	   


Measured memory_bytes: 4108
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int a, b;
	cin >> a >> b;
	cout << ((a <= 9 && b <= 9)? a*b: -1) << endl;

	return 0;
}


Measured memory_bytes: 3636
H, W = map(int, input().split())
s = ["." + input() + "." for _ in range(H)]
s = ["." * (W + 2)] + s + ["." * (W + 2)]
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if s[i][j] == "#":
            if s[i - 1][j] == "#" or s[i + 1][j] == "#" or s[i][j - 1] == "#" or s[i][j + 1] == "#":
                pass
            else:
                print("No")
                exit()
print("Yes")


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
typedef vector<int> Array;
typedef vector<Array> Matrix;
Matrix mul(const Matrix& m, const Matrix& n, int M){
  int N = m.size();
  Matrix res(N, Array(N));
  REP(i, N)REP(j, N)REP(k, N){
    res[i][j] += m[i][k] * n[k][j];
    res[i][j] %= M;
  }
  return res;
}
Matrix make_E(int N){
  Matrix res(N, Array(N));
  REP(i, N) res[i][i] = 1;
  return res;
}
Matrix pow(const Matrix& m, int p, int M){
  int N = m.size();
  if(p == 0) return make_E(N);
  if(p == 1) return m;
  if(p & 1){
    return mul(m, pow(mul(m, m, M), p / 2, M), M);
  }else{
    return pow(mul(m, m, M), p / 2, M);
  }
}

int main(){
  int N, M, A, B, C, T;
  while(cin>>N>>M>>A>>B>>C>>T){
    vector<int> S(N);
    REP(i, N) cin>>S[i];
    Matrix m(N, Array(N));
    REP(i, N)REP(j, N){
      if(i - 1 == j) m[i][j] = A;
      else if(i     == j) m[i][j] = B;
      else if(i + 1 == j) m[i][j] = C;
      else m[i][j] = 0;
    }
    m = pow(m, T, M);
    REP(i, N){
      int ans = 0;
      REP(j, N){
        ans += m[i][j] * S[j];
        ans %= M;
      }
      cout<<ans;
      if(i == N - 1) cout<<endl;
      else cout<<" ";
    }
  }

  return 0;
}

Measured memory_bytes: 1580
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int n;
    cin >> n;
    int ans = 800 * n - (n / 15) * 200;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header
int calc(int n){
	int sum =0;
	while(n>0){
		sum+=n%10;
		n/=10;
	}
	return sum;
}
int main() {
	int n, a, b, ans = 0;
	cin >> n >> a >> b;
	loop(i, 1, n+1){
		int k = calc(i);
		if(k>=a && k<=b) ans+=i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int i,k=0,n,p[100];

    scanf("%d", &n);
    for(i=0;i<n;i++){
       scanf("%d", &p[i]);
       if(p[i] != i+1) k+=1;
    }
    if(k>=3) printf("NO\n");
    else     printf("YES\n");

    return 0;
}


Measured memory_bytes: 128
n,m = map(int,input().split())

p_list=[0]*(n+1)
cnt=[0]*(n+1)
ans=0
plt=0
for i in range(m):
    p,s=map(str,input().split())
    if s == "WA":
        cnt[int(p)] += 1;
    if s == "AC":
        if p_list[int(p)] == 0:
                ans+=1
                plt+=cnt[int(p)]
                p_list[int(p)] += 1
        
print(str(ans) + " " + str(plt))



Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define  rep(i,n) for(li i = 0; i < (n); ++i)
#define  red(i,n) for(li i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;


int main()
{
    char a[10];
    rep(i,9)cin>>a[i];
    cout<<a[0]<<a[4]<<a[8]<<endl;;

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  int total_signboards;
  while(~scanf("%d",&total_signboards)){
    string target_board;
    cin >> target_board;

    int dp[102][102];
    memset(dp,0,sizeof(dp));

    int res = 0;
    for(int i=0;i<total_signboards;i++){
      string old_board;
      cin >> old_board;

      for(int start_pos = 0;start_pos<old_board.size();start_pos++){
	for(int distance = 1;distance<=old_board.size();distance++){
	  string new_board="";
	  new_board.push_back(old_board[start_pos]);
	  int next_pos = start_pos+distance;
	  
	  while(next_pos < old_board.size()){
	    new_board.push_back(old_board[next_pos]);
	    next_pos += distance;
	    if(target_board == new_board){
	      res++;
	      goto found;
	    }
	  }
	}
      }
    found:;
    }
    printf("%d\n",res);
  }
}

Measured memory_bytes: 1300
// Made by Luis Miguel Baez
// es.luismiguelbaez@gmail.com

#include <bits/stdc++.h>
 
using namespace std;

#define endl '\n'
#define precise(n,k) fixed << setprecision(k) << n
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define uint  unsigned int
#define ll    long long
#define ull   unsigned long long
#define ld    long double

#define pii   pair<int, int>
#define piii  pair<int, pair<int, int>>
#define pll   pair<ll, ll>

#define F  first
#define S  second
#define PB push_back
#define MP make_pair

#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool b) {
    return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename T>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const T &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string((T)x);
    }
    res += "}";
    return res;
}

// add templates here

template<class T>
void println(const vector<T> &data) {
    cout << to_string<vector<T>, T>(data) <<endl;
}

template<class T>
void println(const T &data) {
    cout << to_string((T)data) << endl;
}

const int MOD = int(1e9+7);
const int oo  = int(1e9 + 20);
const ll lloo  = (ll)(1e18 + 10);
    
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, a, b;
    cin >> n >> a >> b;
    
    cout << min(n*a, b) << endl;

    return 0;
}

Measured memory_bytes: 3596
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int k = sc.nextInt();
        ArrayList<Long> li = new ArrayList<>();
        for(int i = 0; i < k; i++){
            li.add(sc.nextLong());
        }
        Collections.reverse(li);
        long min = 2;
        long max = 2;
        boolean pos = true;
        for(int i = 0; i < k; i++){
            long now = li.get(i);
            long pow1 = min/now;
            long pow2 = max/now;
            if(pow1 == pow2 && min % now != 0){
                pos = false;
                break;
            }
            if(min % now != 0){
                pow1++;
            }
            min = now*pow1;
            max = now*pow2+now-1;
            //pw.println(now);
        }
        pw.println(pos ? min + " " + max : -1);
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 48936