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

public class Main {
  private static int solve(int n, int[] ss) {
    int sum = 0;
    for (int s : ss) {
      sum += s;
    }
    
    boolean[] dptable = new boolean[sum + 1];
    dptable[0] = true;
    for (int s : ss) {
      for (int i = sum; i >= s; i--) {
        dptable[i] |= dptable[i - s];
      }
    }
    for (int i = sum; i >= 0; i--) {
      if (i % 10 != 0 && dptable[i]) {
        return i;
      }
    }
    return 0;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int[] ss = reader.nextInt(n);
    out.println(solve(n, ss));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 22484
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
        A[i] -= i+1;
    }

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

    int64_t ans = 0;
    for(int i=0; i<N; i++) {
        ans += abs(A[i] - A[N/2]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
    #define all(x) (x).begin(), (x).end()
    typedef long long ll;
    #define MOD 1000000007
    using namespace std;
    ll gcd(ll a, ll b) {
        if(a < b)
            return gcd(b, a);
        ll r = 1;
        while(r != 0) {
            r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
    ll modpow(ll a, ll n, ll mod = MOD) {
        ll res = 1;
        while(n > 0) {
            if(n & 1)
                res = res * a % mod;
            a = a * a % mod;
            n >>= 1;
        }
        return res;
    }
    ll absll(ll a) {
        if ( a >= 0 ) return a;
        return -a;
    }
    ll sign(ll n) {
        if(n >= 0) {
            return 1;
        } else {
            return -1;
        }
    }
    int main() {
        int n;
        cin >> n;
        map<pair<ll, ll>, ll> cnt;
        for(int i = 0; i < n; i++) {
            ll a, b;
            cin >> a >> b;
            if(a == 0 && b == 0) {
                cnt[make_pair(0, 0)]++;
            } else if(a == 0 && b != 0) {
                cnt[make_pair(0, 1)]++;
            } else if(a != 0 && b == 0) {
                cnt[make_pair(1, 0)]++;
            } else {
                if ( a < 0 ) {
                    a *= -1;
                    b *= -1;
                }
                if ( a == 0 && b < 0 ) b *= -1;
                long long int g = gcd( a, b );
                a /= g;
                b /= g;
                cnt[ make_pair( a, b ) ]++;
            }
        }
        ll ans = 1;
        for(auto e : cnt) {
            if(e.second == 0) {
                continue;
            }
            if(e.first == make_pair(0LL, 0LL)) {
                continue;
            }
            pair<ll,ll> ort;
            if(e.first == make_pair(0LL, 1LL)) {
                ort = make_pair(1, 0);
            } else if(e.first == make_pair(1LL, 0LL)) {
                ort = make_pair(0, 1);
            } else {
                long long int ddx = e.first.second;
                long long int ddy = -e.first.first;
                if ( ddx < 0 ) {
                    ddx *= -1;
                    ddy *= -1;
                }
                if ( ddx == 0 && ddy < 0 ) ddy *= -1;
                ort = make_pair( ddx, ddy );
            }
            if ( cnt[ort] == 0 ) {
                ans *= modpow(2, e.second);
                ans %= MOD;
            } else {
                ans *= modpow(2, e.second) + modpow(2, cnt[ort]) - 1;
                ans %= MOD;
                cnt[ort] = 0;
            }
            e.second = 0;
        }
        cout << (cnt[make_pair(0, 0)] + ans - 1 + MOD) % MOD << endl;
    }

Measured memory_bytes: 28424
///*****************************************************///
///*.......................Faiyaj Bin Amin............................*///
///*...................................................................*///
///*.........................KUET CSE 2K17......................*///
///*...................................................*///
///*****************************************************///

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define fastio      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define ret return
#define rep(q, i, n) for(int q=i; q<n; q++)
#define forn(i, n) for(int i=0; i<n; i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define ll long long
#define pb push_back
#define em emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pdd pair<double, double>

#define see(x)        cerr<< __LINE__ << ": " << (#x) << " is "<< (x) <<'\n';
#define seecontent(v) for(auto x : v) { cout << x << " ";} cout << "\n\n";

#define PI 2*acos(0.0)
#define lcm(a, b)  ((a / __gcd(a, b) ) * b)

#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)

#define mx 100005
#define INF 1e18
#define MOD 1000000007
#define MIN 0

//template <typename T>  using orderedSet =
//    tree<T, null_type, less_equal<T>,
//    rb_tree_tag, tree_order_statistics_node_update>; //find_by_order, order_of_key


/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0}; // Directional
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

/**------------------------------------BITMASK------------------------------------------**/
//int Change(int N, int pos){return N= N^(1<<pos);}
//bool Check(int N, int pos){return (bool)(N &(1<<pos));}  /// check bit 0 or 1
/**-----------------------------------------------------------------------------------------------**/

//using namespace __gnu_pbds;
using namespace std;

int main()
{
    fastio;

    ll n;
    cin>>n;

    ll a[n+1], b[n];

    forn(i, n+1)
    {
        cin >> a[i];
    }
    forn(i, n)
    {
        cin >> b[i];
    }

    ll cnt=0;
    forn(i, n)
    {
        ll val = min( (ll) a[i], (ll) b[i]);
        cnt += val;
        b[i]-=val;
        a[i]-=val;

        ll val2 = min( (ll) a[i+1], (ll) b[i]);
        cnt += val2;
        b[i]-=val2;
        a[i+1]-=val2;
    }

    cout<< cnt << "\n";

    return 0;
}


Measured memory_bytes: 5168
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000001
#define r(i,a,b)    for(i=a;i<b;i++)
#define ra(i,a,b)   for(i=a;i<=b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ss          set<ll int>
using namespace std;
 
#define N 1000000
#define M 100000000

struct unit {
  ll int a[N];  
};

ll fact (ll int x)
{if(x==1 || x==0)return 1;
else return x*fact(x-1);}

ll power(ll int x,ll int n)
{if(n==0)return 1;
else if(n%2 == 0)return power(x*x,n/2);
else return x*power(x*x,(n-1)/2);}

bool cmp (const pii&a,const pii&b)
{ return((a.F-a.S) > (b.F-b.S));
/*if(a.S<=b.S){if(a.S==b.S)return a.F<b.F;else return a.S<b.S;}
else return a.S<b.S;*/}


int main()
{
    cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);
  ll i,j,m,n,a,b,h;
  cin>>a>>b>>h>>m;
  if(m==0)
  {
    h=h-1;
    m=60;
  }
  double k = abs(30*h-((11/2.0)*m));
  double l = cos(((2*M_PI)/360)*k);
  double ans = 0;
  //cout<<k<<"\n";
  //cout<<l<<"\n";
  ans=(sqrt(power(a,2)+power(b,2)-(2*a*b*l)));
  cout<<fixed;
  cout<<setprecision(10);
  cout<<ans;
}



Measured memory_bytes: 4244
def actual(N, A, B):
    satisfied_nums = []

    for i in range(1, N + 1):
        sum_of_digits = sum(map(int, str(i)))

        if A <= sum_of_digits <= B:
            satisfied_nums.append(i)

    return sum(satisfied_nums)

N, A, B = map(int, input().split())
print(actual(N, A, B))

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

const int N = 1e5 + 50;

int n, cas, x, y, ans, vis[N], cnt[N];

int main() {
	cin >> n;
	for(int i = 1; i <= n; ++i)
		cnt[i] = 1;
	vis[1] = 1;
	for(cin >> cas; cas--; ) {
		scanf("%d%d", &x, &y);
		vis[y] |= vis[x];
		--cnt[x], ++cnt[y];
		if(!cnt[x]) vis[x] = 0;
	}
	for(int i = 1; i <= n; ++i)
		ans += vis[i];
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1024
n, m = map(int, input().split())
list_score = set([int(input()) for _ in range(m)])

dp = [0] * (n + 1)
mod = pow(10, 9) + 7

dp[0] = 1
if 1 in list_score:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2, n + 1):
    if i not in list_score:
        dp[i] = dp[i - 1] + dp[i - 2]
        dp[i] %= mod

print(dp[n])

Measured memory_bytes: 13216
//بسم الله الرحمن الرحيم
///   ***   ---   |||		 In the name of ALLAH		|||   ---   ***   ///
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define el << endl
#define PI 3.141592653589793238
#define _test_ int t; cin >> t; while(t--)
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define file() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
ll gcd ( ll  a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }
int dx[]={0,0,+1,-1,+1,-1,-1,+1};
int dy[]={+1,-1,0,0,+1,-1,+1,-1};
///*......................*//* LET'S BEGIN (-_^) *//*............................///
const int mx= 1e5+123;
ll  n;

void _case_()
{
    cin >> n;
    
        ll ans=1000000000000000;
        for(auto i=1;i<=sqrt(n);i++)
        {
            if(n%i==0)
            {
                ll k=(n/i)+i-2;
                if(ans>k)
                    ans=k;
            }
        }
        cout << ans el;
}



int main()
{
    optimize();
    //_test_
    _case_();
}

///////////*  N A Y E M  *///////////

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<tuple<string,int,int>> data(N);
  string s;
  int point;
  for(int i=0;i<N;i++){
    cin >> s >> point;
    data.at(i)=make_tuple(s,-point,i+1);
  }
  sort(data.begin(),data.end());
  for(int i=0;i<N;i++){
    cout << get<2>(data.at(i)) << endl;
  }
}


Measured memory_bytes: 3620
def main():
    N, K = map(int, input().split())
    poscs = [0] * (N+1)
    A = list(map(int, input().split()))
    for i in range(N):
        poscs[i+1] = poscs[i] + max(A[i], 0)
    total = sum(A[:K])
    ans = 0
    for i in range(N-K+1):
        tmp = poscs[i] + max(total, 0) + (poscs[N] - poscs[i+K])
        ans = max(ans, tmp)
        if i+K < N:
            total -= A[i]
            total += A[i+K]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 66848
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#define maxn 15
using namespace std;
int n,m;
int match1[maxn],match2[maxn];
char s[maxn][maxn],b[maxn][maxn],can[maxn][maxn];
int judge(int now1,int now2)
{
	for(int k=1;k<=n;k++)
	{
		if(s[k][now1]!=s[match1[k]][now2])
			return false;
	}
	return true;
}
void dfs2(int now,int flag)
{
	if(now==m+1)
	{
		printf("YES\n");
		exit(0);
	}
	if(match2[now])
	{
		dfs2(now+1,flag);
		return;
	}
	if(m&1 && flag && judge(now,now))
	{
		match2[now]=now;
		dfs2(now+1,0);
		match2[now]=0;
	}

	for(int i=now+1;i<=m;i++)
	{
		if(!match2[i] && judge(now,i))
		{
//			cerr<<"+1"<<endl;
			match2[i]=now;
			match2[now]=i+1;

			dfs2(now+1,flag);

			match2[i]=0;
			match2[now]=0;
		}
	}

}
void dfs1(int now,int flag)
{
//	cerr<<now<<endl;
	if(now==n+1)
	{
		dfs2(1,m&1);
		return;
	}
	if(match1[now])
	{
//		cerr<<"+1"<<endl;
		dfs1(now+1,flag);
		return;
	}
	if(n&1 && flag)
	{
//		cerr<<"+1"<<endl;
		match1[now]=now;
		dfs1(now+1,0);
		match1[now]=0;
	}
	for(int i=now+1;i<=n;i++)
	if(!match1[i] && can[now][i])
	{
//		cerr<<"+1"<<endl;
		match1[i]=now;
		match1[now]=i;

		dfs1(now+1,flag);

		match1[i]=0;
		match1[now]=0;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
			scanf("%s",s[i]+1);

	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			b[i][j]=s[i][j];
		}
		sort(b[i]+1,b[i]+1+m);
	}

	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			int flag=1;
			for(int k=1;k<=m;k++)
			if(b[i][k]!=b[j][k])
			{
				flag=0;
			}
			can[i][j]=flag;
//			cerr<<i<<" "<<j<<" "<<flag<<endl;
		}
	}

	dfs1(1,n&1);

	printf("NO\n");
}


Measured memory_bytes: 256
#include<stdio.h>

int partition(int*,int,int);
int main()
{
  int n,i,t;
  scanf("%d",&n);
  int A[n];
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  t = partition(A,0,n-1);
  for(i=0;i<n;i++){
    if(i==t)printf("[");
    printf("%d",A[i]);
    if(i==t)printf("]");
    if(i!=n-1)printf(" ");
                   }
  printf("\n");
  
  return 0;
}

int partition(int *A,int p,int r)
{
    int x,i,j,s;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j]<=x){
            i++;
            s=A[i];
            A[i]=A[j];
            A[j]=s;
        }
    }
    s=A[i+1];
    A[i+1]=A[r];
    A[r]=s;
    
    return i+1;
}



Measured memory_bytes: 2244
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

mod = 10**9 + 7
k = int(input())
s = input()
n = len(s)

def make_tables(n, mod = 10 ** 9 + 7):
    fac = [1, 1] # 階乗テーブル
    finv = [1, 1] #逆元の階乗テーブル
    inv = [0, 1] #逆元テーブル

    for i in range(2, n + 1):
        fac.append((fac[-1] * i) % mod)
        inv.append((mod -inv[mod % i] * (mod // i)) % mod)
        finv.append((finv[-1] * inv[-1]) % mod)
    return fac, finv

def nCk(n, k, mod = 10 ** 9 + 7):
    k = min(k, n-k)
    return fac[n] * finv[k] * finv[n-k] % mod

##########################
fac, finv = make_tables(2*10**6 + 1)
ans = 0
for i in range(k + 1):
    temp = 1
    temp *= pow(26, i, mod)
    temp %= mod
    j = k - i
    temp *= pow(25, j, mod)
    temp %= mod
    temp *= nCk(n + j - 1, n - 1)
    ans += temp
    ans %= mod
print(ans % mod)





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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if((A+B) > (C+D)){
        cout << "Left" << endl;
    }else if((A+B) == (C+D)){
        cout << "Balanced" << endl;
    }else{
        cout << "Right" << endl;
    }


    return 0;
}



Measured memory_bytes: 256
//       In the name of         ****                      God                     ****

/*

Copyright (C)          JadedBeast

                                   Morocco

created : 24/3/2019
	
*/

#include <bits/stdc++.h>

using namespace std;

inline void JadedBeast() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
const int MAX=1e5+1;
vector <int> v[MAX];
int d[MAX],ans=0;
bool used[MAX];
void addEdge(int x, int y ){
	v[x].push_back(y);
}
void dfs(int s){
	used[s]=true;
	for(int x : v[s]){
		if(!used[x])
			dfs(x);
			d[s]=max(d[s],d[x]+1);
			ans=max(d[s],ans);
	}
}
int main(void) {
	JadedBeast();
	int n,m,x,y;

	memset(used,false,sizeof(used));
	memset(d,0,sizeof(d));

	scanf("%d %d",&n,&m);

	for(int i=0; i<m ; i++){
		scanf("%d %d",&x,&y);
		addEdge(x,y);	

	}

	for(int i=1 ;i<=n ;i++)
		if(!used[i])
			dfs(i);

	cout << ans <<endl;
}

Measured memory_bytes: 8320
s = int(input())
a = ['Nan',s]
i = 0
while not(a[i+1] in a[:-1]):
    if a[i+1]%2 == 0:
        a.append(a[i+1] / 2)
    else:
        a.append(a[i+1] * 3 + 1)
    i += 1
print(i + 1)


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;

typedef long long ll;

ll X, K, D;

int main() {
	//No sub撤退しないぞ
	cin >> X >> K >> D;

	if (X == 0) {
		if (K % 2 == 0)cout << 0 << endl;
		else cout << D << endl;
		return 0;
	}

	if (X < 0)X *= -1;
	if (X / D >= K) {
		cout << X - K * D << endl;
		return 0;
	}
	if (X % D == 0) {
		if ((K - (X / D)) % 2 == 0) {
			cout << 0 << endl;
		}
		else cout << D << endl;
		return 0;
	}
	ll rest = K - X / D;
	if (rest % 2 == 0) {
		cout << X % D << endl;
	}
	else cout << D - (X % D) << endl;
	return 0;
}

Measured memory_bytes: 3632
l,r=map(int,input().split())
a=0
b=2019
if r-l>=2018:
   b=0
else:
   for i in range(l,r+1):
        for j in range(i+1,r+1):
            a=i*j%2019
            if b>a:
               b=a
print(b)

Measured memory_bytes: 2940
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;


int main()
{
    //FILE* fp_in = freopen("input.txt","r",stdin);
    int n;
    cin >> n;
    string a,b;
    cin >> a;
    cin >> b;

    ll ans;
    int mae;
    rep(i,n){
        if(i == 0){
            if(a[i] == b[i]){
                ans = 3;
                mae = 0;
            }
            else{
                ans = 6;
                mae = 1;
                i++;
            }
        }
        else{
            if(a[i] == b[i]){
                if(mae==0) ans *= 2;
                else ans *= 1;
                mae = 0;
            }
            else{
                if(mae==0) ans *= 2;
                else ans *= 3;
                i++;
                mae = 1;
            }
        }
        //cout << i << "  " << ans << endl;
        ans %= DIV;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
#define ull unsigned long long 
#define f(i,x,n) for(ll int i=x;i<n;i++) 
#define re(j,x,n) for(int j=x;j>=n;j--)
#define f1(k,x,n) for(int k=x;k<=n;k++)
using namespace std;
int main()
{   
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n,m,b[31]={0},count=0,c;
  cin>>n>>m;
  c=n;
  while(c--)
  { 
    int k;
    cin>>k;
    int a[k];
    f(i,0,k)
    {
      cin>>a[i];
      b[a[i]]++;
    }
  }
   f(i,1,31)
   {
   	 if(b[i]==n)
   	 count++;
   }
   cout<<count;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<pair<pair<string, int>, int> > sp(n);
  REP(i, n) {
    cin >> sp[i].first.first >> sp[i].first.second;
    sp[i].first.second *= -1;
    sp[i].second = i + 1;
  }
  sort(ALL(sp));
  REP(i, n) cout << sp[i].second << '\n';
  return 0;
}


Measured memory_bytes: 256
class RMaxQ:
    
    __slots__ = ["n", "data"]
    
    def __init__(self, li):
        self.n = len(li)
        self.data = li*2
        for i in range(self.n - 1, 0, -1):
            self.data[i] = max(self.data[2*i], self.data[2*i+1])
    
    def update(self, i, a):
        i += self.n
        self.data[i] = a
        while i > 1:
            i //= 2
            self.data[i] = max(self.data[2*i], self.data[2*i+1])
    
    def add(self, i, a):
        i += self.n
        self.data[i] += a
        while i > 1:
            i //= 2
            self.data[i] = max(self.data[2*i], self.data[2*i+1])
    
    def fold(self, l, r):
        l += self.n
        r += self.n
        res = 0
        while l < r:
            if l % 2:
                res = max(self.data[l], res)
                l += 1
            if r % 2:
                r -= 1
                res = max(res, self.data[r])
            l //= 2
            r //= 2
        return res

import sys
input = sys.stdin.readline
n, q = map(int, input().split())
A = list(map(int, input().split()))
seg = RMaxQ(A)
for _ in range(q):
    t, x, v = map(int, input().split())
    x -= 1
    if t == 1:
        seg.update(x, v)
    elif t == 2:
        print(seg.fold(x, v))
    else:
        ng = x
        ok = n+1
        while ok - ng > 1:
            mid = (ok+ng)//2
            if seg.fold(x, mid) >= v:
                ok = mid
            else:
                ng = mid
        print(ok)

Measured memory_bytes: 97032
# 2019/06/22
# AtCoder Beginner Contest 070 - C

import fractions

def lcm_fgf(a, b):
    return int(a * b // fractions.gcd(a, b))

# Input
n = int(input())
alcm = 1

for i in range(n):
    wt = int(input())
    alcm = lcm_fgf(alcm, wt)

# Output
print(alcm)


Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll N=1e6+5,inf=1e18,mod=1e9+7;
#define test ll testcases;cin>>testcases; while(testcases--)
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define sz(x) ((ll)((x).size()))
const ld pi=3.141592653589793238;

bool check_prime(ll n)
{
	ll flag=0,i;
	for(i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			flag=1;
			break;
		}
	}
	if(n==1)
	{
		return false;
	}
	else if(flag==0 || n==2 || n==3)
	{
		return true;
	}
	else
	{
		return false;
	}
}

ll fastexpo(ll a,ll b,ll MOD) 
{
	ll result=1;
	while(b>0)
	{
		if(b%2==1)
		{
			result=(result*a)%MOD;
		}
		a=(a*a)%MOD;
		b=b/2;
	}
	return result;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,k,ans;
    cin>>n;
    ll a[n+1][3],dp[n+1][3];
    for(i=1;i<=n;i++)
    {
    	for(k=0;k<3;k++)
    	{
    		cin>>a[i][k];
    	}
    }
    dp[1][0]=a[1][0];
    dp[1][1]=a[1][1];
    dp[1][2]=a[1][2];
    for(i=2;i<=n;i++)
    {
    	for(k=0;k<3;k++)
    	{
    		dp[i][k]=a[i][k]+max(dp[i-1][(k+1)%3],dp[i-1][(k+2)%3]);
    	}
    }
    ans=max(dp[n][0],max(dp[n][1],dp[n][2]));
    cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 8284
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace ABC046_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = new HashSet<int>();
            var t = scan;
            for (int i = 0; i < 3; i++)
            {
                a.Add(t[i]);
            }
            Console.WriteLine(a.Count());
        }

        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
}


Measured memory_bytes: 3160
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const W = parseInt(arg[0].split(" ")[1]);
 
    const items = arg.slice(1, N + 1).map(n=>n.split(" ").map(l=>parseInt(l)));
    
    /*    
    let dp = [...Array(N+1)].map(n=>[...Array(W+1)].fill(0));

    for(let i=1; i<N+1; i++) {
        const w = wv[i-1][0];
        const v = wv[i-1][1];
        
        for(let j=0; j<W+1; j++) {
            if(w > j) {
                // 単体で重さオーバーなら前回のを引き継ぐ
                dp[i][j] = dp[i-1][j];
            } else {
                dp[i][j] = Math.max(dp[i-1][j], v + dp[i-1][j - w]);
            }
        }
    }
    
    console.log(dp[N][W]);
    */
    
    let dp = []
    for(var i=0;i<W+1;i++) {
        dp.push( Array(N+1).fill(0) );
    }
    
      var result = 0;
  for(var i=0;i<N;i++){
    for(var w=0;w<=W;w++){
 
      var weight = items[i][0]
      var value = items[i][1]
 
      if(weight <= w){
        dp[w][i+1] = Math.max(dp[w][i], dp[w-weight][i] + value);
      }else{
        dp[w][i+1] = dp[w][i];
      }
 
      if(dp[w][i+1] > result){result = dp[w][i+1];}
 
    }
  }
 
  console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 198560
syurui_zairyou = input()
syurui_zairyou = syurui_zairyou.rstrip().split(" ")
syurui = syurui_zairyou[0]
zairyou = syurui_zairyou[1]

donathulist=[]
alldonathu=0
for i in range(int(syurui)):
    donathu = input()
    alldonathu = alldonathu+int(donathu)
    donathulist.append(int(donathu))
    i +=1
    
#print(alldonathu)
#print(donathulist)
donathulist.sort()
#print(donathulist)
print((int(zairyou)-int(alldonathu))//donathulist[0]+int(syurui))
 

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

typedef long long ll;
const int N = 4e3;
int vis[N+10];
char str[N+10];

int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",str+1);
	ll ans = 0;
	for(int i=2;i<n;i++){
		if(str[i]=='R'){
			memset(vis,0,sizeof vis);
			int cnt1 = 0,cnt2 = 0,minus = 0;
			for(int j=i+1;j<=n;j++){
				if(str[j]=='G'){
					cnt1++;
					vis[j-i] = 1;
				}
			}
			for(int j=i-1;j>0;j--){
				if(str[j]=='B'){
					cnt2++;
					if(vis[i-j]){
						minus++;
					}
				}
			}
			ans += (cnt1*cnt2-minus);
			memset(vis,0,sizeof vis);
			cnt1 = 0,cnt2 = 0,minus = 0;
			for(int j=i+1;j<=n;j++){
				if(str[j]=='B'){
					cnt1++;
					vis[j-i] = 1;
				}
			}
			for(int j=i-1;j>0;j--){
				if(str[j]=='G'){
					cnt2++;
					if(vis[i-j]){
						minus++;
					}
				}
			}
			ans += (cnt1*cnt2-minus);
		}
		if(str[i]=='G'){
			memset(vis,0,sizeof vis);
			int cnt1 = 0,cnt2 = 0,minus = 0;
			for(int j=i+1;j<=n;j++){
				if(str[j]=='B'){
					cnt1++;
					vis[j-i] = 1;
				}
			}
			for(int j=i-1;j>0;j--){
				if(str[j]=='R'){
					cnt2++;
					if(vis[i-j]){
						minus++;
					}
				}
			}
			ans += (cnt1*cnt2-minus);
			memset(vis,0,sizeof vis);
			cnt1 = 0,cnt2 = 0,minus = 0;
			for(int j=i+1;j<=n;j++){
				if(str[j]=='R'){
					cnt1++;
					vis[j-i] = 1;
				}
			}
			for(int j=i-1;j>0;j--){
				if(str[j]=='B'){
					cnt2++;
					if(vis[i-j]){
						minus++;
					}
				}
			}
			ans += (cnt1*cnt2-minus);
		}
		if(str[i]=='B'){
			memset(vis,0,sizeof vis);
			int cnt1 = 0,cnt2 = 0,minus = 0;
			for(int j=i+1;j<=n;j++){
				if(str[j]=='R'){
					cnt1++;
					vis[j-i] = 1;
				}
			}
			for(int j=i-1;j>0;j--){
				if(str[j]=='G'){
					cnt2++;
					if(vis[i-j]){
						minus++;
					}
				}
			}
			ans += (cnt1*cnt2-minus);
			memset(vis,0,sizeof vis);
			cnt1 = 0,cnt2 = 0,minus = 0;
			for(int j=i+1;j<=n;j++){
				if(str[j]=='G'){
					cnt1++;
					vis[j-i] = 1;
				}
			}
			for(int j=i-1;j>0;j--){
				if(str[j]=='R'){
					cnt2++;
					if(vis[i-j]){
						minus++;
					}
				}
			}
			ans += (cnt1*cnt2-minus);
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 3808
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

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

int main(){fastio
    string a,b;cin>>a>>b;
    ll as=a.size(),bs=b.size();
    rep(i,0,bs-1)cout<<a[i]<<b[i];
    if(as!=bs)cout<<a[as-1]<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S[] = new String[N];

		for (int i = 0; i < N; i++) {
			S[i] = sc.next();
		}

		Arrays.sort(S);

		int max = 1;

		int b[] = new int[N];
		for(int i=0; i<N; i++) {
			b[i]=1;
		}

		for (int i = 1; i < N; i++) {
			if (S[i].equals(S[i - 1])) {
				b[i] = b[i - 1] + 1;
				if (b[i] > max) {
					max = b[i];
				}
			}
		}

		for (int i = 0; i < N; i++) {
			if (b[i] == max) {
				System.out.println(S[i]);
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 77820
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (s == u) {
        cout << (a - 1) << " " << b << endl;
    }
    else {
        cout << a << " " << (b-1) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int main(void) {

	int N,ans=0;

	cin >> N;

	vector<int>l(N);
	vector<int>r(N);

	for (int i = 0; i < N; i++) {

		cin >> l[i] >> r[i];

		ans = ans + (r[i] - l[i] + 1);

	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#pragma GCC optimize "-O3"
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define LSOne(S) (S & (-S))
#define ll long long
#define two pair<int,int>
#define twol pair<ll,ll>
#define four pair<two,two>
#define pb push_back
#define mk make_pair
#define y1 y1922
#define INF 1000000000000000000
#define P 1000000007
#define lmax 1000000000
#define nn 1000003
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define vi vector<int>
#define vll vector<ll>
#define vtwo vector<two>
#define ALL(container) (container).begin(), (container).end()
#define sz(container) (int)(container.size())
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mid(a,b) (a+b>>1)
#define minN 0
#define maxN 10000000
#define na(x) ((x)<P?(x):(x)-P)
#define ab(a) (-(a)<(a)?(a):-(a))
#define FAST std::ios::sync_with_stdio(false)
#define xRand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rnd rng
#define IT iterator
typedef
tree<
  int,// aq pair<int,int> shegidzlia
  null_type,
  less/*_equal*/<int>,// aqac
  rb_tree_tag,
  tree_order_statistics_node_update>
ordered_set;
// '_equal' mashin ginda roca multiset gchirdeba
template<class key, class value,class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
ordered_map<int, int> my_map;
inline int rin(){
	int x=0,w=1;char ch=getchar();
	while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if (ch=='-') w=0,ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
inline int bin(){
	int x=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x;
}
ll n,a;
multiset<int>s;
multiset<int>::IT it,it1;
vector<two>v;
int main(){FAST;xRand;
cin>>n;
for(int i=1;i<=n;i++){
	cin>>a;
	s.insert(a);
}
while(sz(s)>2){
	it=s.end();
	it--;
	it1=it;
	it--;
	if((*it)<0){
		v.pb({(*it1),(*it)});
		a=(*it);
		s.erase(it);
		it1=s.end();it1--;
		n=(*it1);
		s.erase(it1);
		s.insert(n-a);
		continue;
	}
	it1=s.begin();
	v.pb({(*it1),(*it)});
	n=(*it);
	s.erase(it);
	it1=s.begin();
	a=(*it1);
	s.erase(it1);
	s.insert(a-n);
}
if(sz(s)==2){
	it=s.begin();
	it1=s.end();
	it1--;
	cout<<(*it1)-(*it)<<endl;
	v.pb({(*it1),(*it)});
}
if(sz(s)==1){
	it=s.begin();
	cout<<(*it)<<endl;
}
for(int i=0;i<sz(v);i++){
	cout<<v[i].f<<" "<<v[i].s<<endl;
}
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
                 *   *   * *   *
                  *   *   *   *
                   *   * *   *
                     *  *   *
					   *  *


*/






Measured memory_bytes: 7424
using System;

    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var inputList = input.Split(' ');

            int n = int.Parse(inputList[0]);
            int k = int.Parse(inputList[1]);

            //Console.WriteLine(n);
            //Console.WriteLine(k);
            
            var count = 1;

            while (n / k >= 1)
            {
                n = n / k;
                count++;
            }
            Console.WriteLine(count);
        }
    }



Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int n,x; 
int a[100005];
int main(){
	scanf("%d%d",&n,&x);
	long long ans = 0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]>x){
			ans += a[i]-x;
			a[i] = x;
		}
	}
	for(int i=2;i<=n;i++){
		int res = 0;
		if(a[i]+a[i-1]>x){
			res = a[i]+a[i-1]-x;
			ans += res;
			if(res<=a[i])
				a[i] -= res;
			else{
				res -= a[i];
				a[i-1] -= res;
				a[i] = 0;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
} 

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

const int di[] = {0,1,0,-1};
const int dj[] = {1,0,-1,0};

int main() {
  for(int N; cin >> N && N;) {
    vector<int> pi(N), pj(N);
    for(int i = 1; i < N; ++i) {
      int n, d;
      cin >> n >> d;
      pi[i] = pi[n] + di[d];
      pj[i] = pj[n] + dj[d];
    }
    cout << *max_element(pj.begin(), pj.end())
      - *min_element(pj.begin(), pj.end()) + 1
         << " "
         << *max_element(pi.begin(), pi.end())
      - *min_element(pi.begin(), pi.end()) + 1 << endl;
  }
  return 0;
}

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

using namespace std;

#define int long long
#define rep(i,a,n) for(int i = a; i<n; i++)
#define per(i,a,n) for(int i = n-1; i>=a; i--)

const int INF = 1e9+7;

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

  int a,b,c;
  cin>>a>>b>>c;
  bool poor = false;
  if(a == b && a != c)poor = true;
  if(a == c && a != b)poor = true;
  if(b == c && b != a)poor = true;
  if(poor)cout<<"Yes\n";
  else cout<<"No\n";

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int n;
	cin >> n;
	int g = n % 10;
	if (g == 2 || g == 4 || g == 5 || g == 7 || g == 9) {
		cout << "hon";
		return 0;
	}
	else if (g == 0 || g == 1 || g == 6 || g == 8) {
		cout << "pon";
		return 0;
	}
	else {
		cout << "bon";
	}
}


Measured memory_bytes: 3540
#pragma GCC optimize("Ofast")
#include <cstring>
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
    ll N;
    int i;
    ll acount = 0;

    cin >> N;

    vector<int> A(N);
    vector<int> count(N+1);

    for(i=1; i<=N; i++) {
        cin >> A[i];

        count[A[i]]++;
    }



    for(i=1; i<=N; i++) {
        acount += 1ll*count[i] * (count[i]-1) / 2;
    }

    for(i=1; i<=N; i++) {
        cout << acount - (count[A[i]]-1) << endl;
    }

    return 0;

}

Measured memory_bytes: 4096
N = int(input())
S = input()

count = 0
for h in range(10):
  pos_h = S.find(str(h))
  if pos_h < 0:
    continue
  for i in range(10):
    pos_i = S.find(str(i), pos_h+1)
    if pos_i < 0:
      continue
    for j in range(10):
      pos_j = S.find(str(j), pos_i+1)
      if pos_j < 0:
        continue
      count += 1

print(count)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

class Dice{
public:
    int f[6];

    Dice(){};

    void roll_z(){roll(1,2,4,3);}
    void roll_y(){roll(0,2,5,3);}
    void roll_x(){roll(0,1,5,4);}

    void roll(int a,int b,int c,int d){
        int t = f[a]; f[a] = f[b]; f[b] = f[c]; f[c] = f[d]; f[d] = t;
    }

};

bool chk_dc(Dice dice1, Dice dice2){
    for(int i=0;i<6;i++) if(dice1.f[i] != dice2.f[i]) return false;
    return true; 
}

bool rot_chk(Dice dice1, Dice dice2){
    for(int i=0;i<6;i++){
        for(int j=0;j<4;j++){
            if(chk_dc(dice1,dice2)) return true;
            dice2.roll_z();
        }
        if(i%2 == 0) dice2.roll_y();
        else dice2.roll_x();
    }
    return false;
}

Dice dice[100];int n;

bool check(){
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(rot_chk(dice[i],dice[j])) return false;
        }
    }
    return true;
}


int main(){
    cin >> n;

    for(int i=0;i<n;i++)
        for(int j=0;j<6;j++) cin >> dice[i].f[j];
    
    if(check()) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3092
import java.io.*;
class Main{
    static int heapSize;
    static int[] heapTree;

    public static void main(String[] args){
	BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
	String line = new String();

	//read Tree
	try{
	    line = bin.readLine();
	}
	catch(IOException e){
	    System.out.println("Error");
	}
	heapSize=Integer.parseInt(line);
	heapTree = new int[heapSize+1];

	try{
	    line=bin.readLine();
	}
	catch(IOException e){
	    System.out.println("Error");
	}

	//make Tree
	String[] key = line.split(" ");
	for(int i=1; i<heapTree.length; i++){
	    heapTree[i]=Integer.parseInt(key[i-1]);
	}

	//print
	for(int i=1; i<heapTree.length; i++){
	    System.out.print("node "+i+": key = "+heapTree[i]+","+getParent(i)+getLeft(i)+getRight(i));
	    System.out.println(" ");
	}
    }

    static String getParent(int i){
	if(i/2!=0){
	    return " parent key = " + heapTree[i/2] +",";
	}
	else return "";
    }

    static String getLeft(int i){
	if(2*i<heapSize+1){
	    return " left key = "+heapTree[2*i]+",";
	}
	else return "";
    }

    static String getRight(int i){
	if(2*i+1<heapSize+1){
	    return " right key = "+heapTree[2*i+1]+",";
	}
	else return "";
    }

}

Measured memory_bytes: 9712
import java.math.BigInteger;
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(System.out);

//        int n = sc.nextInt();
            long sum = 0;
            int k = sc.nextInt();
            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int p = 1; p <= k; p++) {
                        sum += gcd(i, j, p);
                    }
                }
            }
            out.println(sum);
//        while (n > 0) {
//            int k = n % 10;
//            if (k == 7) {
//                out.println("Yes");
//                out.flush();
//                out.close();
//                return;
//            }
//            n /= 10;
//        }

//        long sum = 0;
//        for (int i = 1; i<= n; i++) {
//            if (i % 3 != 0 && i % 5 != 0) {
//                sum += i;
//            }
//        }
//        out.println(sum);
//        out.println("No");
        out.flush();
        out.close();
    }

    private static int gcd(int a, int b, int c) {
        BigInteger A = BigInteger.valueOf(a);
        BigInteger B = BigInteger.valueOf(b);
        BigInteger C = BigInteger.valueOf(c);
        return C.gcd(A.gcd(B)).intValue();
    }

    private static void solve(double x, ArrayList<Long> arr, int n) {
        long sum = 0;
        for (int i = 0; i < n; i++) {
            sum += arr.get(i);
        }
        if (1.0 * sum / n >= x) System.out.println(n);
        else {
            Collections.sort(arr);
            long cur = 0;
            long people = 0;
            for (int i = n - 1; i >= 0; i--) {
                cur += arr.get(i);
                people++;
                if (1.0 * cur / people < x) {
                    System.out.println(people - 1);
                    return;
                }
            }
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(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 nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }
}

/**
 *x=3
 * 1 1 2 5
 */

/**
 *
 *  1+1
 **/

Measured memory_bytes: 60012
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(int arg, char* argv[])
{
    int N; cin >> N;

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

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

    cout << A[A.size()-1]-A[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
bool check(int x){
    for(int i=0;i<=sqrt(x);i++){
        if(i*i==x){
            return 1;
        }
    }
    return 0;
}
int main(){
    int n,d;
    cin>>n>>d;
    vector<vector<int>> v(n);
    rep(i,n){
        rep(j,d){
            int x;
            cin>>x;
            v[i].push_back(x);
        }
    }
    int ans = 0;
    rep(i,n){
        for(int j=i+1;j<n;j++){
            int sum = 0;
            rep(k,d){
                sum+=(v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
            }
            if(check(sum)) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    double a, b, x;
    cin >> a >> b >> x;
    if (a * a * b < x * 2) {
        double y = 2 * x / a / a - b;
        double PI = acos(-1);
        double ans = atan2(b - y, a) / PI * 180;
        cout << ans << endl;
    } else {
        double y = 2 * x / a / b;
        double PI = acos(-1);
        double ans = (0.5 - atan2(y, b) / PI) * 180;
        cout << ans << endl;
    }
    return (0^_^0);
}



Measured memory_bytes: 256