akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
int main()
{
   int n,d,x,a[102];
   int sum,tem;
   while(~scanf("%d%d%d",&n,&d,&x))
   {
       //printf("n=%d  d=%d  x=%d  ",n,d,x);
       sum=x;
       for(int i=1;i<=n;i++)
       {
           scanf("%d",&a[i]);
           //printf("a[%d]=%d  ",i,a[i]);
           tem=1;
           for(int j=1;;j++)
           {
               if((a[i]*j+1)<=d)
                tem++;
                else
                    break;
           }
           sum=sum+tem;
           //printf("sum=%d  \n",sum);
       }
       printf("%d\n",sum);
   }
    return 0;
}


Measured memory_bytes: 128
import java.io.*;
import java.util.*;
 
public class Main {
 
	void submit() {
	    int N = nextInt();
	    int[] A1 = new int[N];
	    int[] A2 = new int[N];
	    
	    for(int i=0; i<N; i++){
	        A1[i] = nextInt();
	    }

	    for(int i=0; i<N; i++){
	        A2[i] = nextInt();
	    }
	    
	    int max_total=0;
	    int tmp_total=0;
	    
	    for(int i=0; i<N; i++){
	        tmp_total += A1[i];
	    }
	    tmp_total += A2[N-1];
	    max_total = tmp_total;
	    
	    
	    tmp_total = 0;
	     
	    for(int i=0; i<N; i++){
	        int j, k;
            for(j=0; j<=i; j++){
            	tmp_total += A1[j];            
            }
            for(k=j-1; k<N; k++){
                tmp_total += A2[k];
            }
    	    if(max_total < tmp_total){
    	        max_total = tmp_total;
    	    }
    	    tmp_total = 0;
	    }
	    
        out.println(max_total);
	}

	void preCalc() {
 
	}
 
	void stress() {
 
	}
 
	void test() {
 
	}
 
	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}
 
	static final Random rng = new Random();
 
	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}
 
	public static void main(String[] args) throws IOException {
		new Main();
	}
 
	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
 
	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}
 
	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
 
	int nextInt() {
		return Integer.parseInt(nextToken());
	}
 
	long nextLong() {
		return Long.parseLong(nextToken());
	}
 
	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 21332
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
using namespace std;

int main(){
  
  int n,m;
  cin >> n >> m;
  
  vector<int> k(m);
  vector<vector<int>> s(m, vector<int>(n));
  
  int i,j;
  
  for (i=0; i<m; i++){
    cin >> k[i];
    for (j=0; j<k[i]; j++){
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  
  vector<int> p(m);
  
  for (i=0; i<m; i++){
    cin >> p[i];
  }
  
  vector<int> o(n);
  vector<int> sum(m);
  int ans,flag;
  
  while(true){
    flag=1;
    
    for (i=0; i<m; i++){
      
      sum[i]=0;
      
      for (j=0; j<k[i]; j++){
        sum[i] += o[s[i][j]];
      }
      
      if (sum[i] % 2 != p[i]){
        flag=0;
        break;
      }
    }
    
    if (flag == 1){
      ans++;
    }
    
    o[0]++;
    
    for (i=0; i<n-1; i++){
      if (o[i]==2){
        o[i+1]++;
        o[i]=0;
      }
    }
    
    if (o[n-1]==2){
      break;
    }
  }
  
  cout << ans << endl;
 
  return 0;
}


Measured memory_bytes: 256
N,P = map(int,input().split())
A = list(map(int,input().split()))

odd = 0
for v in A:
    if  v % 2:
        odd += 1 
even = N-odd
if odd != 0:
    print((2**even)*int(2**(odd-1)))
else:
    if P == 0:
        print(2**N)
    else:
        print(0)

Measured memory_bytes: 9140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		IntegralRect rects[] = new IntegralRect[40000];
		for(int i = 0; i < 200; i++){
			for(int j = 0; j < 200; j++){
				rects[i*200 + j] = new IntegralRect(i + 1, j + 1);
			}
		}
		Arrays.sort(rects);
		
		//debug
//		for(int i = 0; i < 100; i++){
//			System.out.println(rects[i].height + " "+ rects[i].width +" " + rects[i].diagonal());
//		}

		while(true){
			String[] tmpArray = br.readLine().split(" ");

			int h = Integer.parseInt(tmpArray[0]);
			int w = Integer.parseInt(tmpArray[1]);

			if(h == 0 && w == 0){
				break;
			}

			IntegralRect tmpRect = new IntegralRect(h, w);
			int diag = tmpRect.diagonal();
//			System.out.println(diag);
			for(int i = 0; i < rects.length ; i++){
//				System.out.println(rects[i].diagonal());
				if(rects[i].compareTo(tmpRect) > 0){
					System.out.println(rects[i].height+" "+rects[i].width);
					break;
				}
			}
		}
	}

}

class IntegralRect implements Comparable<IntegralRect> {
	int height;
	int width;
	public IntegralRect(int h, int w){
		this.height = h;
		this.width = w;
	}


	public int diagonal(){
		if(height >= width){
			return Integer.MAX_VALUE;
		}
		return this.height*this.height + this.width*this.width;
	}


	@Override
	public int compareTo(IntegralRect o) {
		// TODO ?????????????????????????????????????????????
		int d1 = this.diagonal();
		int d2 = o.diagonal();
//		System.out.println(d1+" "+d2);
		return d1 == d2 ? this.height - o.height : d1 - d2;
	}
}

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

pair<ll, ll> invalid(-1, -1);

pair<ll, ll> check(ll l, ll B) {
    ll div = 2 * B / l;
    div -= (l - 1);
    if(div <= 0) return invalid;
    if(div & 1) return invalid;
    else return make_pair(div / 2, l);
}

void chmax(pair<ll, ll> &v1, pair<ll, ll> v2) { if(v1.second < v2.second) v1 = v2; }

bool solve() {
    ll B;
    cin >> B;
    if(!B) return false;
    auto ans = invalid;
    for(ll i = 1; i * i <= 2 * B; i++) {
        if(2 * B % i) continue;
        chmax(ans, check(i, B));
        chmax(ans, check(2 * B / i, B));
    }
    ll N, K;
    tie(N, K) = ans;
    cout << N << ' ' << K << endl;
    return true;
}

int main() {
    while(solve());
    return 0;
}



Measured memory_bytes: 3064
A = input()
B = input()

if len(A)>len(B):
  print("GREATER")
elif len(A)<len(B):
  print("LESS")
else:
  for i in range(len(A)):
    if int(A[i])>int(B[i]):
      print("GREATER")
      break
    elif int(A[i])<int(B[i]):
      print("LESS")
      break
  else:
    print("EQUAL")
      

Measured memory_bytes: 38384
n = int(input())
a = list(map(int, input().split(" ")))
even = []
odd = []
for i in a:
    if i % 2 == 0:
        even.append(i)
    else:
        odd.append(i)

ans = "YES"
if len(odd) % 2 == 1:
    ans = "NO"
print(ans)

Measured memory_bytes: 20128
using System;
using System.Linq;
using System.Collections.Generic;
class c
{
    static void Main()
    {
        var nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var list = new List<int>();
        for (int i = 0; i < nk[0]; i++) list.Add(int.Parse(Console.ReadLine()));
        list = list.OrderBy(f => f).ToList();
        int dif = int.MaxValue;
        for (int i = nk[1] - 1; i < nk[0]; i++)
        {
            dif = Math.Min(dif, list[i] - list[i - nk[1] + 1]);
        }
        Console.WriteLine(dif);
    }
}

Measured memory_bytes: 18652
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        int f = Integer.parseInt(str.substring(0, 2)), t = Integer.parseInt(str.substring(2));
        if (in(f, 1, 12)) {
            System.out.println(in(t, 1, 12) ? "AMBIGUOUS" : "MMYY");
        } else {
            System.out.println(in(t, 1, 12) ? "YYMM" : "NA");
        }
    }

    public static boolean in(int value, int start, int end) {
        return start <= value && value <= end;
    }
}


Measured memory_bytes: 21716
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    int i;
    for(i=0;i<n;i++){
      h[i] = sc.nextInt();
    }
    int total = 1;
    int num = h[0];
    for(i=1;i<n;i++){
      if(h[i]>=num){
        total = total +1;
        num = h[i];
      }else{
        continue;
      }
    }
    System.out.println(total);    
 }
}

Measured memory_bytes: 21460
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main (String[] args) throws java.lang.Exception
	{
		ArrayList<String> array = new ArrayList<String>();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a,  b;
		while(true) {
			array.add(br.readLine());
			String s = array.get(array.size() - 1);
			String[] ary = s.split(" ");
		    if(ary[1].equals("?")) {
		    	break;
		    }
		}
		
		for(int i = 0; i < array.size() - 1; i++) {
			String s = array.get(i);
			String[] ary = s.split(" ");
			a = Integer.parseInt(ary[0]);
			b = Integer.parseInt(ary[2]);
			if(ary[1].equals("+")) {
				System.out.println(a + b);
			}
			if(ary[1].equals("-")) {
				System.out.println(a - b);
			}
			if(ary[1].equals("*")) {
				System.out.println(a * b);
			}
			if(ary[1].equals("/")) {
				System.out.println(a / b);
			}
		}

	}
}

Measured memory_bytes: 24496
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	vector <int> A(N);
	vector< vector<int> > x(N, vector <int> ());
	vector< vector<int> > y(N, vector <int> ());
	for (int ii = 0; ii < N; ++ii){
		cin >> A[ii];
		for (int jj = 0; jj < A[ii]; ++jj){
			int xx, yy;
			cin >> xx >> yy;
			xx--;
			x[ii].push_back(xx);
			y[ii].push_back(yy);
		}
	}

	int ans = 0;
	for (int n = 0; n < (1<<N); ++n){
		bitset< 1<<15 > bs(n);
		bool ok = true;
		for (int ii = 0; ii < N; ++ii){
			if (bs[ii] == 0) continue;
			for (int jj = 0; jj < A[ii]; ++jj){
				int hito = x[ii][jj];
				int honest = y[ii][jj];
				if (bs[hito]){
					if (honest == 0){
						ok = false;
						break;
					}
				} else {
					if (honest == 1){
						ok = false;
						break;
					}
				}
			}
		}
		if (ok){
			int score = bs.count();
			ans = max(ans, score);
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 10000000000LL
#define rep(i,n) for(i=0;i<n;i++)

typedef pair<int,int> pii;

int i,j;
char a[105][105];
int used[105][105];
int h,w;

void search(int x,int y,char c){
    if(x<0 || y<0 || x>=h || y>=w || a[x][y]!=c)return;
    if(used[x][y])return;
    used[x][y]++;
//    printf("x=%d,y=%d",x,y);
    search(x-1,y,c);
    search(x,y-1,c);
    search(x+1,y,c);
    search(x,y+1,c);
    return;
}

int main(void) {
    while(1){
        cin>>h>>w;
        if(h==0 && w==0)break;
        rep(i,h)rep(j,w)used[i][j]=0;
        rep(i,h)
            cin>>a[i];
        int ans=0;
        
        rep(i,h)rep(j,w)if(used[i][j]==0){
            ans++;
           // printf("i=%d,j=%d",i,j);
       //     cout<<endl;
            search(i,j,a[i][j]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define MOD 1000000007
typedef pair<li, li> PI;


li n;
li k;
string s;

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

	li dis = 0;
	char prev = 'X';
	rep(i, n) {
		if (i > 0 && s[i] != prev) {
			dis++;
		}
		prev = s[i];
	}

	li action_num = dis / 2;
	if (k < action_num) {
		cout << n - 1 - (dis - k * 2) << endl;
	} else if (k > action_num) {
		cout << n - 1 << endl;
	} else if (dis % 2 == 0) {
		cout << n - 1 << endl;
	} else {
		cout << n - 2 << endl;
	}



	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int now = 1, cnt = 1;
  while (cnt < n) {
    now = a[now - 1];
    if (now == 2) break;
    cnt++;
  }
  if (now == 2)
    cout << cnt << endl;
  else
    cout << -1 << endl;
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 1;
  for(int i = 0; i < N-1; i++){
    char now = S[i];
    char next = S[i+1];
    if(now == next) continue;
    else ans++;
  }
  cout << ans << endl;
}


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

typedef vector<int> vec1;
typedef vector<vector<int>> vec2;
typedef vector<vector<char>> cvec2;
typedef pair<int, int> pairi;

vec1 vecplus(const vec1 &first, const vec1 &second){
  int length = first.size();
  vec1 answer(length);
  rep(i,length){
    answer.at(i) = first.at(i) + second.at(i);
  }
  return answer;
}

vec2 listmake(const int &row, const int &col){
  vec2 list;
  rep(i,row){
    vec1 v(col);
    rep(j,col){
      cin >> v.at(j);
    }
    list.push_back(v);
  }
  return list;
}

int main(){
  int N, K;
  cin >> N >> K;
  int ans = 0;
  bitset<100> s(0);
  rep(i,K){
    int d;
    cin >> d;
    rep(i,d){
      int A;
      cin >> A;
      s.set(A-1,1);
    }
  }
  rep(i,N){
    if(!(s.test(i))){
      ans++;
    }    
  }  
  cout << ans << endl;
}
  

Measured memory_bytes: 3608
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

ll dp[51][2500] = {};

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

  int N, A;
  cin >> N >> A;

  int x[51] = {};
  for (int i = 1; i <= N; i++) {
    cin >> x[i];
  }
  for (int i = 1; i <= N; i++) {
    for (int j = i - 1; j > 0; j--) {
      for (int k = 0; k <= 2500; k++) {
        if (dp[j][k] > 0) {
          dp[j + 1][k + x[i]] += dp[j][k];
        }
      }
    }
    dp[1][x[i]]++;
  }
  ll cnt = 0;
  for (int i = 0; i <= N; i++) {
    for (int k = 0; k <= 2500; k++) {
      if (dp[i][k] > 0 && k / i == A && k % i == 0) {
        cnt += dp[i][k];
      }
    }
  }

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
const int N = 105;
int main()
{
	int n, a[N] = {0};
	
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	for(int i = n - 1; i >= 0; i--)
	{
		if(i)
		{
			printf("%d ", a[i]);
		}
		else
		{
			printf("%d\n", a[i]);
		}
	}
	
	return 0;
} 


Measured memory_bytes: 3200
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    bool flag = false;
    REP(i,n){
        char in;
        cin>>in;
        if(in=='Y'){
            flag = true;
        }
    }
    if(!flag) print("Three");
    else print("Four");
    return 0;
}

Measured memory_bytes: 256
const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    println(int(input())<2 ? "Hello World" : int(input())+int(input()))
end
main()

Measured memory_bytes: 113604
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    ll n ; 
    cin >> n ; 
    vector<ll> v(n) ; 
    vector<ll> right(n+1) ; 
    for(ll i=0;i<n;i++){
    	cin >> v[i] ; 
    }
    for(ll i=n-1;i>=1;i--){
    	right[i] = right[i+1] + v[i] ;  
    }
    debug() << imie(right) ; 
    ll sum = 0 ;
    ll ans = 1e18 ; 
    for(ll i=0;i<n-1;i++){
    	sum += v[i] ; 
    	ans = min(ans,abs(sum - right[i+1]));
    }
    cout << ans << endl;
    return 0 ;
}


Measured memory_bytes: 3456
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static final int RIGHT = 0, DOWN = 1, LEFT = 2, UP = 3;
	public static Scanner in;
	public static void main(String[] args){
		in = new Scanner(System.in);
		while(true){
			int n = in.nextInt();
			if(n==0) break;
			int m = in.nextInt();
			Figure base = getFigure(m,getArray(m));
			for(int i=1;i<=n;i++){
				m = in.nextInt();
				int[][] ar = getArray(m);
				Figure obj = getFigure(m,ar);
				if(base.equals(obj)){
					System.out.println(i);
				}else{
					obj = getFigure(m,reverseArray(m,ar));
					if(base.equals(obj)){
						System.out.println(i);
					}
				}
			}
			System.out.println("+++++");
			System.gc();
		}
	}
	
	public static int[][] getArray(int m){
		int[][] array = new int[m][2];
		for(int i=0;i<m;i++){
			array[i][0] = in.nextInt();
			array[i][1] = in.nextInt();
		}
		return array;
	}
	
	public static int[][] reverseArray(int m,int[][] base){
		int[][] array = new int[m][2];
		for(int i=0;i<m;i++){
			array[i][0] = base[m-1-i][0];
			array[i][1] = base[m-1-i][1];
		}
		return array;
	}
	
	public static Figure getFigure(int m,int[][] points){
		Figure fig = new Figure();
		int px = points[0][0];
		int py = points[0][1];
		int x = points[1][0];
		int y = points[1][1];
		int direction;
		if(x==px){
			fig.len.add(Math.abs(y - py));
			if(y-py>0) direction = UP;
			else direction = DOWN;
		}else{
			fig.len.add(Math.abs(x - px));
			if(x-px>0) direction = RIGHT;
			else direction = LEFT;
		}
		for(int i=2;i<m;i++){
			px = x;
			py = y;
			x = points[i][0];
			y = points[i][1];
			if(x==px){
				if(direction==RIGHT){
					fig.turnR.add((y-py>0)?false:true);
				}else{
					fig.turnR.add((y-py>0)?true:false);
				}
			}else{
				if(direction==UP){
					fig.turnR.add((x-px>0)?true:false);
				}else{
					fig.turnR.add((x-px>0)?false:true);
				}
			}
			if(x==px){
				fig.len.add(Math.abs(y - py));
				if(y-py>0) direction = UP;
				else direction = DOWN;
			}else{
				fig.len.add(Math.abs(x - px));
				if(x-px>0) direction = RIGHT;
				else direction = LEFT;
			}
		}
		return fig;
	}
}

class Figure{
	ArrayList<Integer> len;
	ArrayList<Boolean> turnR;
	
	public Figure(){
		len = new ArrayList<Integer>();
		turnR = new ArrayList<Boolean>();
	}
	
	@Override
	public boolean equals(Object o){
		Figure f = (Figure) o;
		return 
			len.equals(f.len) && 
			turnR.equals(f.turnR);
	}
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

template <typename S>
struct sparseTable {
    using T = typename S::T;
    int n;
    vector<int> log2;
    vector<vector<T>> t;

    sparseTable(int nn) {
        n = nn;
        log2.assign(n+1, 0);
        for(int i=2; i<=n; ++i) log2[i] = log2[i >> 1] + 1;
        t = vector<vector<T>>(log2[n]+1, vector<T>(n));
    }
    void init(vector<T> v) {
        for(int i=0; i<n; ++i) t[0][i] = v[i];
        for(int j=1; j<=log2[n]; ++j) {
            int w = 1LL<<(j-1);
            for (int i = 0; i+(w<<1) <= n; ++i) {
                t[j][i] = S::op(t[j-1][i], t[j-1][i+w]);
            }
        }
    }
    // [l, r]
    T query(int l, int r) {
        int j = log2[r - l];
        return S::op(t[j][l], t[j][r-(1 << j)+1]);
    }
};

// 集合T、結合則・可換・冪等律が成り立つ二項演算op
struct minnimum {
    using T = ll;
    static T op(const T& a, const T& b) { return min(a, b); }
};

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    // auto f = [](ll a, ll b){ return min(a, b); };
    // auto g = [](ll a, ll b) { return b; };
    // segtree<ll> seg(n, f, g, INF);
    // seg.build(a);

    sparseTable<minnimum> seg(n);
    seg.init(a);

    ll ret = 0;
    REP(i, n) {
        // a[i]が最小になる区間
        ll lb=-1, ub=i;
        while(ub-lb>1) {
            ll mid = (lb+ub)/2;
            if(seg.query(mid, i) >= a[i]) ub = mid;
            else lb = mid;
        }
        ll l=ub;
        lb=i, ub=n;
        while(ub-lb>1) {
            ll mid = (lb+ub)/2;
            if(seg.query(i, mid) >= a[i]) lb = mid;
            else ub = mid;
        }
        ll r = lb;

        ret += (i-l+1) * (r-i+1) * a[i];
    }
    cout << ret << endl;

    return 0;
}


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

int main(void) {
	// vector
	std::vector<std::pair<long long, int>> prices;
	
	// input
	int n, m;
	std::cin >> n >> m;
	std::vector<long long> a(n);
	std::vector<int> b(n);
	for(int i = 0; i < n; ++i) {
		std::cin >> a[i] >> b[i];
		prices.push_back(std::make_pair(a[i], b[i]));
	}

	// sort
	std::sort(prices.begin(), prices.end(), [](std::pair<long long, int> lhs, std::pair<long long, int> rhs){ return lhs.first < rhs.first;});

	// sum
	long long money = 0;
	int n_drink = 0;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < prices[i].second; ++j) {
			money += prices[i].first;
			++n_drink;
			if(n_drink == m) goto _end;
		}
	}
	
	_end:
	std::cout << money << std::endl;

	return 0;
}


Measured memory_bytes: 3572
check_flg = True
while True:

    H, W = [int(x) for x in input().split()]
    if H == 0 and W == 0: break

    for i in range(H):
        check_flg = True if i % 2 == 0 else False
        for j in range(W):
            if check_flg:
                print("#", end='')
            else:
                print(".", end='')
            check_flg = not check_flg
        print("\n", end="")
    print("\n", end="")

Measured memory_bytes: 9100
S = input()
r_num = 0
flag = True

for s in S:
    if s == 'R' and flag:
        r_num += 1
    elif s == 'R' and (flag == False):
        if r_num == 0:
            r_num += 1
        flag = True
    else:
        flag = False

print(r_num)

Measured memory_bytes: 9104
package main

import (
	"fmt"
	"unicode/utf8"
)

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

	inputs := scanNums(N)

	// fmt.Println(inputs)

	res := 0
	for i := 0; i < len(inputs)-2; i++ {
		a := inputs[i]
		b := inputs[i+1]
		c := inputs[i+2]

		if (a < b && b < c) || (c < b && b < a) {
			// fmt.Println(a, b, c)
			res++
		}
	}
	fmt.Println(res)

}

func scanStrings(len int) (strings []string) {
	var str string
	for i := 0; i < len; i++ {
		fmt.Scanf("%s", &str)
		strings = append(strings, str)
	}
	return
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func spritString(input string) (res []string) {
	for i := 0; i < utf8.RuneCountInString(input); i++ {
		res = append(res, input[i:i+1])
	}
	return
}


Measured memory_bytes: 512
(stdin => {
  // Define Function
  const nsort = (array) => array.sort((x, y) => x - y).join(' ')
  // Declare Variable
  const inputs = stdin.toString().trim().split('\n')
  const nlist = inputs.slice(0, -1)
    .map(v => v.split(' ').map(Number))

  // Main
  const result = Array.from(nlist, nsort)
  // Display
  console.log(result.join('\n'))
})(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 18052
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ep emplace_back
#define st first
#define sc second

using namespace std;

const ll mod = 998244353;
const int e = 1e6 + 69;
const int base = 311;

// dung igt thay cho gt luc tinh giai thua
// 3
// cach tao hoan vi tu n so : n*(n+1)/2;

struct kien
{
    ll x, y;
};
kien a[e];

bool lf(const kien &p, const kien &q)
{
    return p.x <q.x;
}

int main()
{
   ll n, m;
   cin >> n >> m;
   for(int i=1; i<=n; i++)
   {
       cin >> a[i].x >> a[i].y;
   }
   sort(a+1, a+n+1, lf);
   ll s = 0;
   for(int i=1; i<=n; i++)
   {
       s += a[i].x * min(m, a[i].y);
       m -= min(m, a[i].y);
       if(m == 0) break;
   }
   cout << s;

}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
const ll inf=1e18;
vector<ll>dp;
vector<ll>pre;

void rec(int i,vector<int>&not_taken,ll score_so_far,int mask,int group){
	if(i==(int)not_taken.size()){
		dp[mask]=max(dp[mask],score_so_far+pre[group]);
		return;
	}
	rec(i+1,not_taken,score_so_far,mask,group);
	rec(i+1,not_taken,score_so_far,mask^(1<<not_taken[i]),group^(1<<not_taken[i]));
	}
void solve(){
	int n;
	cin>>n;
	vector<vector<int>>in(n,vector<int>(n));
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>in[i][j];
		}
	}
	dp.resize(1<<n,-inf);
	pre.resize(1<<n);
	for(int mask=0;mask<(1<<n);mask++){
		for(int i=0;i<n;i++){
			if(mask&(1<<i)) {
                for (int j = i + 1; j < n; j++) {
                    if (mask & (1 << j)) {
                        pre[mask] += in[i][j];
                    }
                }
            }
		}
	}
		
	dp[0]=0;
	for(int mask=0;mask<(1<<n);mask++){
		vector<int>not_taken;
		for(int i=0;i<n;i++){
			if(!(mask&(1<<i))){
				not_taken.push_back(i);
			}
		}
		rec(0,not_taken,dp[mask],mask,0);
	}
	
	cout<<dp[(1<<n)-1]<<endl;
	
	
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)solve();
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};

int main(){
  int n,q;
  cin >> n >> q;
  char s[n+1];
  int w[n+1];
  cin >> s;
  int ams=0;
  w[0]=0;
  rep(i,n-1){
    if(s[i]=='A'&&s[i+1]=='C'){
      ams++;
    }
    w[i+1]=ams;
  }
  w[n]=ams;
  int l[q],r[q];
  rep(i,q){
    cin >> l[i] >> r[i];
    cout << w[r[i]-1]-w[l[i]-1] << endl;
  }
}


Measured memory_bytes: 2048
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <string>

#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define fro(j,a,b) for(int j=a;j<b;j++)
#define pb push_back

using namespace std;

int main(){
    string s;
    int n;
    cin>>n>>s;
    int count=0;
    pan(i,n-2){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
            count++;
        }
    }
    cout<<count;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
using ll = long long; constexpr int inf = INT_MAX / 2; constexpr ll infl = 1LL << 60;
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }

bool IsNgNum(int n, vector<bool>& NG) {
  while (n) {
    if (NG[n % 10]) return true;
    n /= 10;
  }
  return false;
}

void _main() {
  int N, K;
  cin >> N >> K;
  vector<bool> D(10, false);
  rep(i, 0, K) {
    int t;
    cin >> t;
    D[t] = true;
  }

  while (IsNgNum(N, D)) N++;
  cout << N << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
    int k, x;
    
    cin >> k >> x;
    if(500 * k >= x) {
        cout << "Yes" <<endl;
    }
    else {
        cout << "No" << endl;
    }

    
    

}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;
void solve()
{
	bool flag=true;
	//Enter your code here Tanmay:)
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	for(int i=0;i<n;i++)
	{
		if(arr[i]%2==0)
		{
		if(arr[i]%3==0||arr[i]%5==0)
			flag=true;
		else
		{
			flag=false;
			break;
		}
	}
	}
	if(flag)
		cout<<"APPROVED";
	else
		cout<<"DENIED";
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}
/*
int eulortotent(int n)
     {
    //Enter your code here Tanmay:)
    int total=n;
        for(int p=2;p*p<=n;p++)
        {
            if (n%p==0)
        {
            total /= p;
            total *= (p-1);
            while ( n % p == 0 ) 
                n /= p;
        }
    }

    if(n>1)
    {
        total/=n;
        total*=(n-1);
    }

  return total;
}
*/

Measured memory_bytes: 256
/*
ABC154A - Remaining Balls
*/

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

int main()
{
	char s[11], t[11], u[11];
	int a, b;

	scanf("%s%s%d%d%s", s, t, &a, &b, u);

	if (strcmp(s, u) == 0) {
		a = a - 1;
	} else {
		b = b - 1;
	}

	printf("%d %d\n", a, b);

	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main()
{
 int counts[4];
 int temp;
 int i;
 int twos=0;
 int ones=0;

 counts[0]=0;
 counts[1]=0;
 counts[2]=0;
 counts[3]=0;
 for(i=0;i<6;i++)
 {
   scanf("%d",&temp);
   counts[temp-1]++;
 }
 for(i=0;i<4;i++) 
 {
  if(counts[i]==2) twos++;
  if(counts[i]==1) ones++;
 }

 if((twos==2)&&(ones==2))
 {
  printf("YES\n");
 }else{
  printf("NO\n");
 }

 return 0;
}

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

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define MP make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;


int main(){
    string s;
    while(cin>>s){
        if(s=="0")break;
        int a=0,b=0;
        rep(i,1,s.length()){
            if(s[i]=='A')a++;
            else b++;
        }
        (a>b)?a++:b++;
        cout<<a<<" "<<b<<endl;
    }

    
    return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e3+10;
ll dp[55][55][105];
ll n,ara[55],k;
ll cholo(ll l,ll r,ll k){
    if(k==0) return 0;
    if(r<l){
        if(l>r) return 0;
    }

    ll &ret=dp[l][r][k];
    if(~ret)  return ret;
    ll sum=0;
    if(ara[l]>=0) sum=ara[l]+cholo(l+1,r,k-1);
    else if(ara[l]<0){
        if(k>1) sum=max(sum,cholo(l+1,r,k-2));
        sum=max(sum,ara[l]+cholo(l+1,r,k-1));
    }

    if(ara[r]>=0) sum=max(sum,ara[r]+cholo(l,r-1,k-1));
    else if(ara[r]<0){
        if(k>1) sum=max(sum,cholo(l,r-1,k-2));
        sum=max(sum,ara[r]+cholo(l,r-1,k-1));
    }

    return (ret=sum);
}
int main()
{
    Khela
    ll a,b,c,i,j,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>n>>k)
    {
        for(i=0;i<n;i++)  cin>>ara[i];
        memset(dp,-1,sizeof dp);
        ll ans=cholo(0,n-1,k);
        cout<<ans<<endl;
    }




}

Measured memory_bytes: 2688
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m];
		int[] b = new int[m];
		int[] c = new int[n];
		
		for(int i=0; i<m; i++){
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		
		for(int i=0; i<m; i++){
			if (a[i] == 1){
				c[b[i]-1] ++; 
			}
			if (b[i] == n){
				c[a[i]-1] ++;
			}
		}
		
		int j = 0;
		while(j < n){
			if (c[j] == 2){
				System.out.println("POSSIBLE");
				return;
			}
			j++;
		}
		System.out.println("IMPOSSIBLE");
		
		sc.close();
	}

}


Measured memory_bytes: 103696
from sys import stdin


def heisei_or_tbd(date_string):
    year, month, day = date_string.split('/')
    int_date = int(year+month+day)
    ########print(int_date)
    if int_date <= 20190430:
        return 'Heisei'
    else:
        return 'TBD'


def main():
    input_line = stdin.readline().rstrip()
    answer = heisei_or_tbd(input_line)
    print(answer)


if __name__ == '__main__':
    main()


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

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

void extgcd(ll a, ll b, ll &x, ll &y) {
  if(b == 0) {
    x = 1;
    y = 0;
    return;
  }
  extgcd(b, a%b, y, x);
  y -= a/b*x;
  return; 
}

ll mod_inverse(ll a, ll m = mod) {
  ll x, y;
  extgcd(a,m,x,y);
  return (m + x % m) % m;
}

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = Pow(2,n);
  ans--;
  ll ca = 1, cb = 1;
  for(ll i = 1; i <= a; i++) {
    (ca *= mod_inverse(i)) %= mod;
    (ca *= (n+1-i)) %= mod;
  }
   for(ll i = 1; i <= b; i++) {
    (cb *= mod_inverse(i)) %= mod;
    (cb *= (n+1-i)) %= mod;
  }
  ans = (((ans - ca - cb) % mod) + mod) % mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        return s.Substring(0,3);
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 25792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
    ll n;
    cin >> n;
    vector<ll> arr(n);
    ll val=0;
    for(ll i=0;i<n;i++)
    {
        cin >> arr[i];
        val^=arr[i];
    }
    vector<ll> pre_xor(n,val);
    for(ll i=0;i<n;i++)
    {
        ll out=arr[i]^pre_xor[i];
        cout << out <<" ";
    }

}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1e9+7;


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

    bool f=true;
    for(int k=1;k<N;k++){
        if(p[k]<p[k-1]){
            f=false;
            break;
        }
    }
    if(f){
        cout<<"YES"<<endl;
        return 0;
    }

    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            int tmp=p[i];
            p[i]=p[j]; p[j]=tmp;
            bool flag=true;
            for(int k=1;k<N;k++){
                if(p[k]<p[k-1]){
                    flag=false;
                    break;
                }
            }
            if(flag){
                cout<<"YES"<<endl;
                return 0;
            }
            tmp=p[i];
            p[i]=p[j]; p[j]=tmp;

        }
    }

    cout<<"NO"<<endl;
    return 0;
}



Measured memory_bytes: 256
import numpy as np
n = int(input())
s = list(input())

ans = s.count('R') * s.count('G') * s.count('B')

#print(ans)
for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2 * j - i
        if k < n:
            #print(i,j,k)
            if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
                ans -= 1

print(ans)

Measured memory_bytes: 27100
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

    int n = sc.nextInt();
    int m = sc.nextInt();

    int[][] a = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        a[i][j] = sc.nextInt();
      }
    }

    int[][] ans = new int[n][m];

    for (int i = 0; i < m; i++) {      
      int b = sc.nextInt();
      for (int j = 0; j < n; j++) {
        ans[j][i] = a[j][i] * b;
      }
    }

    for (int[] x : ans) {
      pw.println(Arrays.stream(x).sum());
    }

    pw.flush();
    sc.close();
  }
}


Measured memory_bytes: 43164
import java.util.Scanner;
public class Main {
 private static Scanner sc;
 public static void main(String[] args){
  int i,x;
  sc = new Scanner(System.in);
  int n = sc.nextInt();
  for(i=3;i<=n;i++){
	  x=i;
	   if(n<3||n>10000)break;
 
	   if(x%3==0){
  	     System.out.print(" "+i);continue;
     }else if(x%10==3){
  	     System.out.print(" "+i);continue;
     }
      
      if(x>10 && x<=100){
    	  x=i;
          x/=10;
          if(x==3 && x%10!=0){                
       	   System.out.print(" "+i);continue;  
          }
      }
      
      else if(x>100 && x<=1000){
   	      x=i;
          x=x-(x/100)*100;                    
          x/=10;
          if(x==3 && x%10!=0){
       	   System.out.print(" "+i);continue;
          }
          x=i;
          x/=100;
          if(x==3 && x%100!=0){
       	   System.out.print(" "+i);continue;
          }
      }
      
       
      else if(x>1000 && x<=10000){
   	      x=i;
          x=x-(x/1000)*1000;
          x=x-(x/100)*100;
          x/=10;
          if(x==3 && x%10!=0){
       	   System.out.print(" "+i);continue;
          }
          x=i;
          x=x-(x/1000)*1000;
          x/=100;
          if(x==3 && x%100!=0){
       	   System.out.print(" "+i);continue;
          }
          x=i;
          x/=1000;
          if(x==3 && x%1000!=0){
       	   System.out.print(" "+i);continue;
          }
      }
  }
  
  System.out.println();
 }
}

Measured memory_bytes: 28888
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

bool comp(const string& i, const string& j){
	return (i > j);
}
int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int n, a;
	cin >> n >> a;
	n%=500;
	if(n > a) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

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

k = 55555
eratos = [0 for i in range(k+1)]
prime = []
prime_bool = {}
for i in range(2, k+1):
    if eratos[i] == 1:
        prime_bool[i] = 0
        continue
    prime.append(i)
    prime_bool[i] = 1
    for j in range(2, k+1):
        if i * j > k:
            break
        eratos[i*j] = 1

ans = []
m = 11
while len(ans) < n:
    if prime_bool[m] == 1 and m % 5 == 1:
        ans.append(m)

    m += 2

print(" ".join([str(a) for a in ans]))


Measured memory_bytes: 9540
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const long long MOD = 1000000007;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<>;


void solve(long long n, std::vector<long long> a){
    vector<i64> cnt(63, 0);

    mint ans = 0;
    int i = 0;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < 63; ++j){
            bool fl = ((a[i] >> j) & 1);
            i64 null = fl ? (i - cnt[j]) : cnt[j];
            ans += mint(null) * mint(1LL << j);
            if(fl)
                ++cnt[j];
        }
    cout << *ans << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 2560