akhauriyash/Code-Regression huggingface dataset:
X, K, D = map(int, input().split())
X = abs(X)
a = X // D
b = X % D

if X >= D*K:
    print (X - K*D)
else:
    if (K - X//D) % 2 == 0:
        print (X - X//D * D)
    else:
        print (D - (X - X//D * D))


Measured memory_bytes: 9092
import sys
sys.setrecursionlimit(10**6)

def m():
    H, W = map(int, input().split())
    S = []
    for i in range(H):
        S.append(list(input()))

    graph = [[[]for _ in range(W)] for _ in range(H)]
    visited = [[0 for _ in range(W)] for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == ".":
                continue
            if S[max(i - 1, 0)][j] == ".":
                graph[max(i - 1, 0)][j].append((i,j))
                graph[i][j].append((max(i - 1, 0),j))

            if S[min(i+1, H-1)][j] == ".":
                graph[min(i + 1, H - 1)][j].append((i,j))
                graph[i][j].append((min(i + 1, H - 1),j))

            if S[i][max(j - 1, 0)] == ".":
                graph[i][max(j - 1, 0)].append((i,j))
                graph[i][j].append((i,max(j - 1, 0)))

            if S[i][min(j+1, W-1)] == ".":
                graph[i][min(j + 1, W - 1)].append((i,j))
                graph[i][j].append((i,min(j+1, W-1)))

    bw = [0] * 2
    def dfs(g):
        for a,b in g:
            if visited[a][b] == 1:
                continue
            visited[a][b] = 1
            if S[a][b] == ".":
                bw[0] += 1
            else:
                bw[1] += 1
            dfs(graph[a][b])

    ans = 0
    for i in range(H):
        for j in range(W):
            if visited[i][j] == 1:
                continue
            bw[0], bw[1] = 0, 0
            dfs(graph[i][j])
            ans += bw[0] * bw[1]

    return ans

print(m())

Measured memory_bytes: 252356
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,m,ans=0;
  double a[105]={},cnt=0;
  cin >> n >> m;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    cnt+=a[i];
  }
  for(int i=0; i<n; i++) {
    if(a[i]>=cnt/(4*m)) {
      ans++;
    }
  }
  if(ans<m) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

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

class DisjointSet {
    public:
        DisjointSet() {}
        DisjointSet(int size) {
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i != size; ++i) makeSet(i);
        }

        void makeSet(int x) {
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x, int y) {
            return findSet(x) == findSet(y);
        }

        int findSet(int x) {
            if (x != p[x]) {
                p[x] = findSet(p[x]);
            }
            return p[x];
        }

        void unite(int x, int y) {
            link(findSet(x), findSet(y));
        }

        void link(int x, int y) {
            if (rank[x] > rank[y]) {
                p[y] = x;
            } else {
                p[x] = y;
                if (rank[x] == rank[y]) {
                    rank[y]++;
                }
            }
        }
    private:
        vector<int> rank, p;
};

int main()
{
    int n, q, a, b;
    int t;
    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);
    for (int i = 0; i != q; ++i)
    {
        cin >> t >> a >> b;
        if (t == 0)
        {
            ds.unite(a, b);
        }
        else
        {
            cout << ds.same(a, b) << endl;
        }
    }
    return 0;
}


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

int main(){
    int H,W;
    char s[52][52];
    cin >> H >> W;
    for(int i=0;i<52;i++){
        for(int j=0;j<52;j++){
            s[i][j] = '.';
        }
    }
    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            cin >> s[i][j];
        }
    }
    bool no_flag=false;
    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            if(s[i][j] == '.'){
                continue;
            }else{
                if(s[i-1][j] == '.' && s[i+1][j] == '.' && s[i][j-1] == '.' && s[i][j+1] == '.'){
                    no_flag=true;
                    break;
                }
            }

        }
    }
    
    if(no_flag){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    
}


Measured memory_bytes: 256
#include <stdio.h>

int hantei(int *r, int N) {
	for (int i = 1; i <= N - 1; i++) {
		if (r[i] > r[i + 1]) return 0;
	}
	return 1;
}

int main()
{
	int ret;

	int N;
	int p[51];
	int q[51];

	ret = scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		ret = scanf("%d", &(p[i]));
	}

	ret = hantei(p, N);
	if (ret == 1) {
		printf("YES");
		goto end;
	}

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

			for (int k = 1; k <= N; k++) {
				q[k] = p[k];
			}
			q[j] = p[i];
			q[i] = p[j];

			ret = hantei(q, N);
			if (ret == 1) {
				printf("YES");
				goto end;
			}

		}
	}

	printf("NO");

end:
	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

ll in_t, tmp=0, cnt=0;
int main() {
	in(ll, N);
	vector<ll> sum(N+1);
	loop(i, N){
		cin >> in_t;
		sum[i+1] = sum[i] + in_t;
	}

	//loop(i, N+1) cerr << sum[i] << ", "; cerr << endl;
	sort_v(sum);
	//loop(i, N+1) cerr << sum[i] << ", "; cerr << endl;

	auto add = [&](ll n){
		//cerr << "add: " << n << endl;
		cnt += n*(n-1)/2;
	};

	tmp = 1;
	loop(i, N){
		if(sum[i+1] == sum[i])
			++tmp;
		else{
			add(tmp);
			tmp = 1;
		}
		//cerr << "tmp: " << tmp << endl;
	}
	add(tmp);

	out(cnt);
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using tiii = tuple<int,int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const ll DIV =1e9+7;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
int main(){
  int a,b; cin >> a >> b;
  cout << 6 - a - b << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void)
{
  string s;
  cin>>s;
  
  if(s[0]=='a'){
    if((s[1]=='b')&&(s[2]=='c')){puts("Yes"); return 0;}
    if((s[1]=='c')&&(s[2]=='b')){puts("Yes"); return 0;}
  }
  
  if(s[0]=='b'){
    if((s[1]=='a')&&(s[2]=='c')){puts("Yes"); return 0;}
    if((s[1]=='c')&&(s[2]=='a')){puts("Yes"); return 0;}
  }
  
  if(s[0]=='c'){
    if((s[1]=='a')&&(s[2]=='b')){puts("Yes"); return 0;}
    if((s[1]=='b')&&(s[2]=='a')){puts("Yes"); return 0;}
  }
  
  puts("No");
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
long long combination2(long long n)
{
	return n * (n - 1) / 2;
}
 
 
int main()
{
	int N;
	cin >> N;
	vector<int> balls(N+1);
	vector<int> count(N+1);
	//unordered_multiset<int> ballscount;
 
 
 
	long long ans = 0;
	long long tot = 0;
 
	for (int i = 1; i <= N; i++)
	{
		int a;
		cin >> a;
		balls[i] = a;
	}
 
	for (int i = 0; i <= N; i++)
	{
		count[balls[i]]++;
	}
 
	for (int i = 0; i <= N; i++)
	{
		tot += combination2(count[i]);
	}
 
 
 
	for (int i = 1; i <= N; i++)
	{
		ans = tot;
		ans -= combination2(count[balls[i]]);
		ans += combination2(count[balls[i]] - 1);
		cout << ans << endl;
	}
 
 
 
	return 0;
}

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

int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}

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

	int count = 0;
	for (int i = 0; i < 1000; ++i)
	{
		int c[3];
		c[0] = i / 100;
		c[1] = (i - c[0] * 100) / 10;
		c[2] = i - c[1] * 10 - c[0] * 100;

		int l = 0;
		for (; l < N; ++l)
		{
			if (ctoi(S[l]) == c[0])
			{
				break;
			}
		}
		
		int m = l + 1;
		for (; m < N; ++m)
		{
			if (ctoi(S[m]) == c[1])
			{
				break;
			}
		}

		int n = m + 1;
		for (; n < N; ++n)
		{
			if (ctoi(S[n]) == c[2])
			{
				break;
			}
		}

		if (n < N)
		{
			++count;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};


int main(void){
    int N;
    cin >> N;
    vector<vector<bool>> F(N, vector<bool>(10));
    vector<vector<int>> P(N, vector<int>(11));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 10; j++){
            int x;
            cin >> x;
            F[i][j] = x;
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 11; j++){
            cin >> P[i][j];
        }
    }
    int ans = -INT_MAX;
    for(int i = 1; i <= (1 << 10) - 1; i++){
        int res = 0;
        vector<bool> joisino(10);
        int I = i;
        for(int j = 0; j < 10; j++){
            joisino[j] = I % 2;
            I /= 2;
        }
        for(int j = 0; j < N; j++){
            int cnt = 0;
            for(int k = 0; k < 10; k++){
                if(F[j][k] && joisino[k]) cnt++;
            }
            res += P[j][cnt];
        }
        ans = max(ans, res);
    }
    cout << ans << endl;
}


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

int main() {
	long int n;
	cin>>n;
	long long int a[n];
	for(long int i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n,greater<long long int>());
	long long int ans=0,cur=0,t1=0;
	for(long int i=1;i<n;i++)
	{
	    if(i==1)
	    {
	        ans+=a[cur];
	        cur++;
	    }
	    else
	    {
	        t1++;
	        ans+=a[cur];
	        if(t1==2)
	        {
	            t1=0;
	            cur++;
	        }
	    }
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 5184
from itertools import product

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]

ans = 0
for hl in product([0, 1], repeat=h):
    for wl in product([0, 1], repeat=w):
        cnt = 0
        for ci, hi in zip(c, hl):
            for cij, wj in zip(ci, wl):
                if hi == 0 and wj == 0:
                    cnt += (cij == '#')
        ans += (cnt == k)
print(ans)


Measured memory_bytes: 74380
#include<bits/stdc++.h>
using namespace std;
int main(){
    int r,d,x2000;
    cin>>r>>d>>x2000;
    int i;
    for(i=0;i<10;i++){
        cout<<r*x2000-d<<endl;
        x2000=r*x2000-d;
    }
}

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

struct Card{
  char suit;
  int value;
};

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

void merge(struct 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(struct 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(struct Card A[],int n,int p,int r){
  int i,j;
  struct 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(struct 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;
  struct Card A[MAX],B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%s %d",S,&v);
    A[i].suit = B[i].suit = 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].suit != B[i].suit)stable = 0;
  }

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

  return 0;
}



Measured memory_bytes: 4068
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<pair<int,int>> vip;

#define ZOOM ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define LOOP_IT(s) for(auto it=(s).begin();it!=(s).end();++it)

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

    int n,m;
    cin>>n>>m;
    int tot = n+m;
    tot = ((tot)*(tot-1))/2;
    cout<<tot-(n*m);

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define D double
#define lli long long int
#define testcase int t;cin>>t;while(t--)
#define fast_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define P pair<int,int>
/*bool isprime(lli n)
{
    if(n==1) return 0;
    for(lli i=2;i<=n/2;i++)
    {
        if(n%i==0) return 0;
    }
    return 1;
}
bool issemiprime(lli n)
{
    for(int i=2;i<n;i++)
    {
        if(isprime(i)&&isprime(n/i)&&n%i==0&&i!=n/i){
            return 1;
        }
    }
    return 0;
}
lli extendedgcd(lli q,lli r1,lli r2,lli r,lli s1,lli s2,lli s,lli t1,lli t2,lli t)
{
if(r2==0) return r1;
	r1=r2;
        r2=r;
        s1=s2;
        s2=s;
        t1=t2;
        t2=t;
        q=r1/r2;
        r=r1%r2;
        s=s1-(s2*q);
        t=t1-(t2*q);
return extendedgcd(q,r1,r2,r,s1,s2,s,t1,t2,t);
}
lli gcd(lli a,lli b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
void SOE()
{
    for(lli i=2;i<=100000;i++)
    {
        if(sieve[i]) continue;
        for(lli x=i;x<=100000;x+=i)
        {
            sieve[x]+=1;
        }
    }
}*/
/*bool func(pair<int,int> a,pair<int,int> b)
{
    return a.first<b.first;
}
int dfs(vector<vector<int>> g,int n)
{
    if(g[n].size()==0) return 0;
    if(dp[n]!=-1) return dp[n];
    for(auto x:g[n])
    {
        dp[n]=max(dp[n],1+dfs(g,x));
    }
    return dp[n];
}*/
void solve()
{
    int n,k;
    cin>>n>>k;
    bool dp[k+1];
    memset(dp,false,sizeof(dp));
    set<int> s;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        s.insert(a);
    }
    dp[0]=false;
    for(int i=1;i<k+1;i++)
    {
        for(auto x:s)
        {
            if((i-x)>=0&&(dp[i-x]==false))
            {
                dp[i]=true;
                break;
            }
        }
    }
    if(dp[k]==true) cout<<"First";
    else cout<<"Second";

}
int main()
{
    fast_io;
    solve();
}


Measured memory_bytes: 3708
#include <stdio.h>
 
void rotate_S(int minase_inori[6]) {
    int hayami_saori = minase_inori[0];
    minase_inori[0] = minase_inori[4];
    minase_inori[4] = minase_inori[5];
    minase_inori[5] = minase_inori[1];
    minase_inori[1] = hayami_saori;
}
 
void rotate_NES(int kugimiya_rie[6]) {
    int kitamura_eri = kugimiya_rie[1];
    kugimiya_rie[1] = kugimiya_rie[3];
    kugimiya_rie[3] = kugimiya_rie[4];
    kugimiya_rie[4] = kugimiya_rie[2];
    kugimiya_rie[2] = kitamura_eri;
}
 
int check(const int asumi_kana[6], const int iguti_yuka[6]) {
    int sakura_ayane;
    int satou_satomi[6];
    for (sakura_ayane = 0; sakura_ayane < 6; sakura_ayane++) {
        satou_satomi[sakura_ayane] = iguti_yuka[sakura_ayane];
    }
    for (sakura_ayane = 0; sakura_ayane < 4; sakura_ayane++) {
        int tateno_kanako;
        for (tateno_kanako = 0; tateno_kanako < 6; tateno_kanako++) {
            if (asumi_kana[tateno_kanako] != satou_satomi[tateno_kanako]) break;
        }
        if (tateno_kanako >= 6) {
            return 1;
        }
        rotate_NES(satou_satomi);
    }
    return 0;
}
 
int tokui_sora(const int utida_maaya[6], const int taneda_risa[6]) {
    int igarasi_hiromi[6];
    int horie_yui;
    for (horie_yui = 0; horie_yui < 6; horie_yui++) {
        igarasi_hiromi[horie_yui] = taneda_risa[horie_yui];
    }
    if (check(utida_maaya, igarasi_hiromi)) return 1;
    for (horie_yui = 0; horie_yui < 4; horie_yui++) {
        rotate_NES(igarasi_hiromi);
        rotate_S(igarasi_hiromi);
        if (check(utida_maaya, igarasi_hiromi)) return 1;
        rotate_S(igarasi_hiromi);
        rotate_S(igarasi_hiromi);
        rotate_S(igarasi_hiromi);
    }
    rotate_S(igarasi_hiromi);
    rotate_S(igarasi_hiromi);
    return check(utida_maaya, igarasi_hiromi);
}
 
int main(void) {
    int mizuhasi_kaori;
    int ootani_ikue[100][6];
    int uesaka_sumire, suzaki_aya;
    if (scanf("%d", &mizuhasi_kaori) != 1) return 1;
    for (uesaka_sumire = 0; uesaka_sumire < mizuhasi_kaori; uesaka_sumire++) {
        for (suzaki_aya = 0; suzaki_aya < 6; suzaki_aya++) {
            if (scanf("%d", &ootani_ikue[uesaka_sumire][suzaki_aya]) != 1) return 1;
        }
    }
    for (uesaka_sumire = 0; uesaka_sumire < mizuhasi_kaori; uesaka_sumire++) {
        for (suzaki_aya = uesaka_sumire + 1; suzaki_aya < mizuhasi_kaori; suzaki_aya++) {
            if (tokui_sora(ootani_ikue[uesaka_sumire], ootani_ikue[suzaki_aya])) {
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
}



Measured memory_bytes: 2148
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>
#include <complex>

using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const int INF = (1<<30);
const ll INFL = (1LL<<62);
const ll MOD = 1000000007;
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> ll mod_pow(ll a, ll n, T mod) { mod=(ll)mod; ll res=1, p=a%mod; while(n){ if(n&1) res=res*p%mod; p=p*p%mod; n>>=1; } return res; }
template<int mod>
struct ModInt {
    using ll = long long; ll x;
    ModInt() : x(0) {}
    ModInt(int y) : x(y >= 0 ? ll(y % mod) : (ll)((mod - (-y) % mod))) {}
    ModInt(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod)) {}
    ModInt &operator+=(const ModInt &rhs) { if((x += rhs.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &rhs) { if((x += mod - rhs.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &rhs) { x = x * rhs.x % mod; return *this; }
    ModInt &operator/=(const ModInt &rhs) { *this *= rhs.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(const ModInt &rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(const ModInt &rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(const ModInt &rhs) const { return ModInt(*this) /= rhs; }
    ModInt operator==(const ModInt &rhs) const { return x == rhs.x; }
    ModInt operator!=(const ModInt &rhs) const { return x != rhs.x; }
    friend ostream &operator<<(ostream &os, const ModInt &rhs) { return os << rhs.x; }
    friend istream &operator>>(istream &is, ModInt &rhs) { ll t; is >> t; rhs = ModInt<mod> (t); return (is); }
private:
    ModInt inverse() const { ll a = x, u = 1LL, v = 0LL, t, b = (ll)mod; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return  ModInt(u); }
};
using mint = ModInt<MOD>;

int main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N, Q;
    string S;
    cin >> N >> Q >> S;
    vector<int> sum(N+1, 0);
    rep(i, N){
        sum[i+1] = sum[i];
        if(S[i]=='A' && S[i+1] == 'C') sum[i+1] += 1;
    }
    // rep(i, N+1) cout << i << " ";
    // cout << "\n";
    // rep(i, N+1) cout << sum[i] << " ";
    // cout << "\n";
    while(Q--){
        int l, r;
        cin >> l >> r;
        l--, r--;
        cout << sum[r] - sum[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1488
package main

import (
	"fmt"
	"math"
	"sort"
)

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

	var S = make(SortBy, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&S[i].rest, &S[i].rank)
		S[i].i = i + 1
	}
	sort.Sort(S)
	for i := 0; i < N; i++ {
		fmt.Println(S[i].i)
	}
}

/*  ----------------------------------------  */

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type restaurant struct {
	rest string
	rank int
	i    int
}
type SortBy []restaurant

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i].rest == a[j].rest {
		return a[i].rank > a[j].rank
	} else {
		return a[i].rest < a[j].rest
	}
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main() {
	int n, b, f, r, v, x[4][3][10] = { 0 }, i, j, k;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> b >> f >> r >> v;
		x[b - 1][f - 1][r - 1] += v;
	}
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 10; k++) {
				cout << " " << x[i][j][k];
			}
			cout << endl;
		}
		if (i != 3) {
			for (k = 0; k<20; k++)
				cout << '#';
			cout << endl;
		}
	}

}

Measured memory_bytes: 1160
/*
 * A.cpp
 *
 *  Created on: 2020/07/25
 *      Author: 17k1028
 */



#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define REPD(i,n) for(ll i=n-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=a; i<=ll(b); i++)
#define FORD(i,a,b) for(ll i=a; i>=ll(b); i--)

int main(){
	string s;
	ll X;
	cin >> X;
	if (400<=X && X<=599){
		s = "8";
	}
	else if (600<=X && X<=799){
		s = "7";
	}
	else if (800<=X && X<=999){
		s = "6";
	}
	else if (1000<=X && X<=1199){
		s = "5";
	}
	else if (1200<=X && X<=1399){
		s = "4";
	}
	else if (1400<=X && X<=1599){
		s = "3";
	}
	else if (1600<=X && X<=1799){
		s = "2";
	}
	else if (1800<=X && X<=1999){
		s = "1";
	}
	cout << s << endl;
}





Measured memory_bytes: 3548
from bisect import bisect_left
N,M = map(int,input().split())
C = {i:[] for i in range(1,N+1)}
city = [0 for _ in range(M+1)]
for j in range(1,M+1):
    p,y = map(int,input().split())
    C[p].append((y,j))
    city[j]=(p,y)
for p in C:
    if len(C[p])>0:
        C[p] = sorted(C[p],key=lambda x:x[0])
for j in range(1,M+1):
    p,y = city[j]
    ind = bisect_left(C[p],(y,j))
    p = str(p)
    if len(p)<6:
        p ="0"*(6-len(p))+p
    x = str(ind+1)
    if len(x)<6:
        x = "0"*(6-len(x))+x
    print(p+x)

Measured memory_bytes: 82452
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <queue>
#include <unordered_map>
#include <list>
#include <set>
#include <numeric>
using namespace std;

using ll = long long;

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

template<typename T>
constexpr T divide_ceil(T a, T b)
{
	T remainder = a % b;
	return remainder == 0 ? a / b : (a + (b - remainder)) / b;
}

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

	cout << divide_ceil(N, 1000) * 1000 - N << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	double h;
	vector<double> high;
	while(cin>>h){
		high.push_back(h);
	}
	sort(high.begin(),high.end());
	cout<<high[high.size()-1]-high[0]<<endl;
	return 0;
}

Measured memory_bytes: 1304
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double db;
typedef vector<ll> VI;
typedef vector<pair<ll,ll> > VII;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
//
#define M 1000000007
#define INF (ll)0x3f3f3f3f3f3f3f3f
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define itr iterator
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}

void error_out() { cerr << endl; }
template <typename Head, typename... Tail>
void error_out(Head H, Tail... T) {
  cerr << " " << H;
  error_out(T...);
}
void time_elapsed(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}
#ifndef ONLINE_JUDGE
#define error(...) cerr << "[" << #__VA_ARGS__ << "]:", error_out(__VA_ARGS__)
#define fioe() fileioe()
#define time() time_elapsed()
#else
#define error(...) 1
#define fioe() 1
#define time() 1
#endif


//
int main()
{
	GO
	//fioe();
	ll h,n;
	cin>>h>>n;
	ll arr[n+3];
	ll sum=0;
	for(ll i=0;i<n;i++){
		cin>>arr[i];
		sum+=arr[i];
	}
	if(h>sum){
		cout<<"No"<<endl;
	}
	else{
		cout<<"Yes"<<endl;
	}
	time();
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<cmath>
#include<numeric>
#include<queue>
using namespace std;


int main(void) {

  int n;
  while(cin >> n){
    if( n == 0 ) break;

    int w, h;
    cin >> w >> h;
    vector< vector<bool> > a(h, vector<bool> (w, false));
    for(int i=0; i<n; i++){
      int x, y;
      cin >> x >> y;
      a[y-1][x-1] = true;
    }
    int s, t;
    cin >> s >> t;

    int mx = 0;
    for(int i=0; i<=h-t; i++){
      for(int j=0; j<=w-s; j++){
        int cnt = 0;
        for(int k=0; k<t; k++){
          for(int l=0; l<s; l++){
            if( a[i+k][j+l] ) cnt++;
          }
        }
        mx = max(mx, cnt);
      }
    }
    cout << mx << endl;


  }



  return 0;
}








//

Measured memory_bytes: 3160
/* ex6-2
   Sagzar1993  */

#include <stdio.h>
#include <string.h>

#define SIZE 256

int main(void) {
    int length, mid;
    char words[SIZE];

    //文字列の入力
    fgets(words, SIZE, stdin);

    //文字列の長さを取得
    length = strlen(words);
    //先頭と語尾の間の文字数
    mid = length - 3;

    putchar(words[0]); //先頭文字を出力
    printf("%d", mid); //間の文字数を出力
    putchar(words[length-2]); //最後の文字を出力
    printf("\n"); //改行
    
    return 0;  
}

Measured memory_bytes: 128
using System;
    class Program
    {
        static void Main(string[] args)
        {
            string[] xInputMax = Console.ReadLine().Split(' ');
            int xMaxX = int.Parse(xInputMax[0]);
            int xMaxY = int.Parse(xInputMax[1]);

            string[] xInputX = Console.ReadLine().Split(' ');
            long xSumX = SumAreaLength(xInputX, xMaxX);

            string[] xInputY = Console.ReadLine().Split(' ');
            long xSumY = SumAreaLength(xInputY, xMaxY);

            long xDivisor = 1000000007;
            Console.WriteLine(((xSumX % xDivisor) * (xSumY % xDivisor)) % xDivisor);
        }

        static long SumAreaLength(string[] input, int maxCount)
        {
            long xSum = 0;
            for (int i = 0; i < maxCount; ++i)
            {
                xSum += long.Parse(input[i]) * (2 * i - maxCount + 1);
            }
            return xSum;
        }
    }

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

#define N 1000000
bool prime[N + 5] = {0};

void sprime() {
  prime[0] = 1;
  prime[1] = 1;
  for(int i = 2; i * i <= N; ++i)
    if(!prime[i])
      for(int j = 2; i * j <= N; ++j) prime[i * j] = 1;
}

long long x;

int main() {
  sprime();
  cin >> x;
  for(int i = x; i < N; ++i)
    if(!prime[i]) {
      cout << i << endl;
      return 0;
    }
  return 0;
}

Measured memory_bytes: 1280
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	var (
		s, c    string
		q, t, f int
	)

	nextReader = newScanner()
	s = nextString()
	q = nextInt()

	rev := false
	dq := list.New()
	dq.PushFront(s)
	for i := 0; i < q; i++ {
		t = nextInt()
		if t == 1 {
			rev = !rev
		}
		if t == 2 {
			f, c = nextInt(), nextString()
			if f == 1 {
				if rev {
					dq.PushBack(c)
				} else {
					dq.PushFront(c)
				}
			}
			if f == 2 {
				if rev {
					dq.PushFront(c)
				} else {
					dq.PushBack(c)
				}
			}
		}
	}
	ss := make([]string, dq.Len())
	i := 0
	for e := dq.Front(); e != nil; e = e.Next() {
		ss[i] = e.Value.(string)
		i++
	}

	ans := strings.Join(ss, "")
	if rev {
		ans = reverse(ans)
	}
	fmt.Println(ans)
}

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

// ---------------------------------------------------------------
// I/O
// ---------------------------------------------------------------
var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}


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

using namespace std;

typedef long long int ll;

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

  int n, k;
  cin >> n >> k;
  vector < int > a (n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort (a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < k; i++) ans += a[i];
  cout << ans << '\n';
}


Measured memory_bytes: 3652
#include <stdio.h>
//#include <string.h>

int main() {
    char inLetter, outLetter;

    for (int i = 0; i < 1200; ++i) {
        scanf("%c", &inLetter);

        if (inLetter == 44) {
            printf(",");
            continue;
        } else if (inLetter == 32) {
            printf(" ");
            continue;
        } else if (inLetter == 46) {
            printf(".");
            continue;
        }

        if (inLetter == 10) {
            printf("\n");
            return 0;
        }

        if (inLetter >= 97 && inLetter <= 122) {
            // lowercase
            outLetter = inLetter - 32;
        } else if (inLetter >= 65 && inLetter <= 90){
            outLetter = inLetter + 32;
        } else
            outLetter = inLetter;

        printf("%c", outLetter);
    }
    return 0;
}


Measured memory_bytes: 2040
n = int(input())
A = list(map(int, input().split()))

dp = [0] * (10**6+1)

for a in A:
    dp[a] += 1

ans = 0

for i in range(10**6+1):
    if dp[i] == 1:
        ans += 1
    if dp[i] != 0:
        for j in range(2*i, 10**6+1, i):
            if dp[j] != 0:
                dp[j] += 1

print(ans)

Measured memory_bytes: 32376
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;


void solve(long long S, long long W){

    if( W >= S ){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }

    return;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long S;
    scanf("%lld",&S);
    long long W;
    scanf("%lld",&W);
    solve(S, W);
    return 0;
}


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

int main(){
	int n,x ;
	cin >> n >> x ;
	int d = 0 ;
	int ans = 1 ;
	for(int i=0;i<n;i++){
		int l ; cin >> l ;
		d += l ;
		if(d<=x) ans++ ;
		else{
			cout << ans << endl ;
			return 0 ;
		}
	}
    cout << ans << endl ;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) { 
	int i, a, b;
	char op;
	for (i = 0 ;; i++) {
		scanf("%d %c %d", &a, &op, &b);
		if (op == '+') {
			printf("%d", a + b);
		}
		else if (op == '-') {
			printf("%d", a - b);
		}
		else if (op == '*') {
			printf("%d", a * b);
		}
		else if (op == '/') {
			printf("%d", a / b);
		}
		else if (op == '?') {
			break;
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2024
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
using namespace std;
int save[100000][20];
int now[20];
int n, m, Q, tot;
void dfs(int index, int p){
    if(index == n){
        for(int i=0; i<n; i++){
            save[tot][i] = now[i];
        }
        tot++;
        return;
    }
    if(index > n){
        return;
    }
    for(int i=p; i<=m; i++){
        now[index] = i;
        dfs(index+1, i);
    }
}
void init(){
    tot = 0;
    dfs(0, 1);
}

int qu[60][10];

int get_sum(int index){
    int sum = 0;
    for(int i=0; i<Q; i++){
        if(save[index][ qu[i][1]-1 ] - save[index][ qu[i][0]-1 ] ==  qu[i][2]){
            sum += qu[i][3];
        }
    }
    return sum;
}

int main(){
    cin>>n>>m>>Q;
    init();
    for(int i=0; i<Q; i++){
        cin>>qu[i][0]>>qu[i][1]>>qu[i][2]>>qu[i][3];
    }
    int maxx = 0;
    for(int i=0; i<tot; i++){
        int now = get_sum(i);
        if(now >= maxx){
            maxx = now;
        }
    }
    cout<<maxx<<endl;
    return 0;
}


Measured memory_bytes: 10784
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  int N;
  string S;
  cin >> N >> S;

  int ans = 0;
  REP(i, N-2) if(S[i] == 'A') if(S[i+1] == 'B') if(S[i+2] == 'C') ans++;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

R,C,K=map(int,input().split())
J=[tuple(map(int,input().split())) for i in range(K)]

#DP0=[[0]*(C+2) for i in range(R+2)]
DP1=[[0]*(C+2) for i in range(R+2)]
DP2=[[0]*(C+2) for i in range(R+2)]
DP3=[[0]*(C+2) for i in range(R+2)]

MAP=[[0]*C for i in range(R)]

for x,y,v in J:
    MAP[x-1][y-1]=v

for i in range(R):
    for j in range(C):
        DP1[i][j]=max(DP1[i][j-1],DP1[i-1][j]+MAP[i][j],DP2[i-1][j]+MAP[i][j],DP3[i-1][j]+MAP[i][j])
        DP2[i][j]=max(DP2[i][j-1],DP1[i][j-1]+MAP[i][j])
        DP3[i][j]=max(DP3[i][j-1],DP2[i][j-1]+MAP[i][j])

ANS=0
for i in range(R):
    for j in range(C):
        ANS=max(ANS,DP1[i][j],DP2[i][j],DP3[i][j])
print(ANS)



Measured memory_bytes: 382712
def main():
    N = int(input())
    X = [list(map(int,input().split())) for _ in range(N)]
    def num(i,j):
        r = int((i*j)**(0.5))
        if r**2 == i*j:
            if i == j:
                print((r-1)*2)
            else:
                print((r-1)*2-1)
        else:
            if r*(r+1) >= i*j:
                print((r-1)*2)
            else:
                print(r*2-1)

    for i in range(N):
        num(X[i][0],X[i][1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, c) = in.readLine.split(" ").map(_.toInt)
  val dcf = Iterator.continually(in.readLine)
    .take(c).map(_.split(" ").map(_.toInt)).toArray
  val pallet = Iterator.continually(in.readLine)
    .take(n).map(_.split(" ").map(_.toInt - 1)).toArray

  val table = Array.ofDim[Int](3,c)
  for {
    k <- 0 until c
    i <- 0 until n
    j <- 0 until n
  } {
    table((i+j)%3)(k) += dcf(pallet(i)(j))(k)
  }

  // debug(table.mkString(" "))

  def dfsEnum(d:Int, n:Int):Int = {
    // d進 n個列挙
    val enum = Array.ofDim[Int](n)
    var ret = Int.MaxValue
  
    def evalute():Unit = {
      if(enum.toSet.size == 3) {
        val res = 
          enum.indices.map(i => table(i)(enum(i))).sum
        ret = math.min(ret, res)
        // debug(enum.mkString(" "), " ", res)
      }
    }
  
    def dfs(cnt:Int):Unit = {
      if(cnt == n) evalute
      else {
        for(i <- 0 until c) {
          enum(cnt) = i
          dfs(cnt+1)
        }
      }
    }
  
    dfs(0)
    ret
  }

  val ans = dfsEnum(c,3)
  println(ans)

  def debug(any:Any*):Unit = {
    if(this.getClass.toString != "class Main$")
      println(any.mkString(" "))
  }
}

Measured memory_bytes: 47680
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom = label
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = self.rear , self.bottom, self.front, self.top
    def print_top(self):
        print(self.top)
  
label = list(map(int,input().split()))
op_list = list(input())
d = dice(label)
for op in op_list:
    d.roll(op)
d.print_top()


Measured memory_bytes: 5600
/* 
	بسم الله الرحمن الرحیم
	
	(; طلا یک جهانی
*/

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

const int MAX_N = 4000 + 5, MOD = 924844033;
int fac[MAX_N] = {1}, head[MAX_N], dp[MAX_N][MAX_N], m[MAX_N], n, k;
bool mark[MAX_N];

int dfs(int v) {
	mark[v] = true;
	int t = v + (v < n? +1: -1) * n;
	vector<int> adj = {t - k, t + k};
	int res = 1;
	for (int u: adj)
		if (u >= 0 && u < 2 * n && ((v < n) != (u < n)) && !mark[u]) 
			res += dfs(u);
	return res;
}

void find_m() {
	int sz = 0;
	for (int i = 0; i < 2 * n; i++)
		if (!mark[i]) {
			head[sz + 1] = true;
			sz += dfs(i) - 1;
		}
	for (int i = 0; i <= sz; i++)
		dp[0][i] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= sz; j++)
			dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 2 + head[j]]) % MOD;
	for (int i = 0; i <= n; i++)
		m[i] = dp[i][sz];
}

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		fac[i] = 1LL * fac[i - 1] * i % MOD;
	find_m();
	int ans = 0;
	for (int i = 0, s = 1; i <= n; i++, s *= -1)
		ans = (ans + 1LL * s * m[i] * fac[n - i]) % MOD;
	cout << (ans + MOD) % MOD;
}


Measured memory_bytes: 33152
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/assoc_container.hpp> 
using namespace std; using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_mset;

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define F0R(i,a) for(int i = 0; i < a; i++)
#define F0Rd(i,a) for (int i = a - 1; i >=0 ; i--)
#define FORd(i,a,b) for (int i = b - 1; i >= a; i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define newl '\n'

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define print(x) cout << x << newl;
#define finish(x) return cout << x << "\n", 0;
#define bug(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " " << 

const int MXN = 2e5 + 5;
//const int MXN = 1e6 + 5;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;



int N;
ll dp[100002][101], a, K;

int main(){ FAST
	//ifstream cin("/Users/konwoo/input.txt");
	//ofstream cout("/Users/konwoo/output.txt");

    cin >> N >> K;
    ll pref = 0;
    FOR(i,1,N+1){
        cin >> a;
        pref += a;
        if (i == 1){
            F0R(j,a+1) dp[j][1] = 1;
            continue;
        }
        dp[0][i] = 1;
        FOR(j,1,min(pref,K)+1){
            dp[j][i] = (dp[j-1][i] + dp[j][i-1]) % INF;
            ll sub = (j > a ? dp[j-a-1][i-1] : 0);
            dp[j][i] = (dp[j][i] - sub) % INF;
            if (dp[j][i] < 0) dp[j][i] += INF;
        }
    }
    finish(dp[K][N]);




















	return 0;
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int N;
    cin >> N;
    
    string S;
    cin >> S;

    if (N % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    
    for(int i = 0; i < N/2; i++) {
        if (S[i] != S[i + N/2]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
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;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    int N;cin>>N;
    bool G[N+1][N+1];
    REP(i,N+1)REP(j,N+1)G[i][j]=true;
    REP(i,N+1)G[i][i]=false;
    if(N%2==0){
        cout<<(N-2)*N/2<<endl;
        REPS(i,N){
            G[i][N-i+1]=false;
        }
    }
    else{
        cout<<(N-1)*(N-1)/2<<endl;
        REPS(i,N){
            G[i][N-i]=false;
        }
    }
    REPS(i,N)REPS(j,N)if(G[i][j]){
        cout<<i<<" "<<j<<endl;
        G[i][j]=G[j][i]=false;
    }
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n,m;
vll a;
unordered_map<lli,lli> b;
lli ans = 0;

int main(){
  cin >> n >> m;
  a = vll(n+1);
  for(lli i = 1;i <= n;i++) cin >> a[i];
  for(lli i = 1;i <= n;i++) a[i] += a[i-1];
  for(lli i = 0;i <= n;i++){
    b[a[i]%m]++;
  }
  for(auto x : b){
    lli y = x.second;
    ans += y*(y-1)/2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4492
def main():
    N, M = map(int, input().split())
    sc = [tuple(map(int, input().split())) for _ in range(M)]
    i_from = 10**(N-1) if N > 1 else 0
    i_to = 10**N
    for i_str in map(str, range(i_from, i_to)):
        if all(len(i_str) >= s and i_str[s-1] == str(c) for s, c in sc):
            print(i_str)
            return
    print(-1)

main()


Measured memory_bytes: 3064
import itertools as itr

A=list(map(int,input()))

b=list(itr.product(range(2),repeat=3))


for i in b:
    i=['+' if j==1 else '-' for j in i]
    ans=A[0]
    if i[0]=='+':
        ans+=A[1]
    else:
        ans-=A[1]

    if i[1]=='+':
        ans+=A[2]
    else:
        ans-=A[2]    

    if i[2]=='+':
        ans+=A[3]
    else:
        ans-=A[3] 

    if ans==7:
        C=[]
        C.append(A[0])
        C.append(i[0])
        C.append(A[1])
        C.append(i[1])
        C.append(A[2])
        C.append(i[2])
        C.append(A[3])
        C.append('=7')
        print(''.join(map(str,C)))
        exit(0)   


print(-1)
    

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

typedef long long int ll;
typedef string str;

int main ()
{
	ll t,n,m=0,k,i,j,a,b;
	cin  >> a >> b >> n;
	if(n<b)
		m=n;
	else
		m=b-1;
	cout << (a*m)/b - a*(m/b) << endl;
	return 0;
}

Measured memory_bytes: 3676