akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;

int n, m , q;
vector<int> a, b, c, d;
int ans = 0;

void dfs(vector<int> A) {
  if (A.size() == n+1) {
    int now = 0;
    rep(i, q) {
      if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
    }
    ans = max(ans, now);
    return;
  }
  
  A.push_back(A.back());
  while (A.back() <= m) {
    dfs(A);
    A.back()++;
  }
}

int main() {
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i, q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1, 1));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <cstdlib>
#include <iostream>

namespace {

const int N = 8;
// the positions of k-queens are fixed.
// Once initialized, the values remain unchanged.
bool row[N] = {false};

bool col[N] = {false};
bool down[2 * N - 1] = {false};
bool up[2 * N - 1] = {false};
int pos[N] = {-1, -1, -1, -1, -1, -1, -1, -1};

void Print() {
  for (int r = 0; r < N; ++r) {
    const int qc = pos[r];
    for (int c = 0; c < N; ++c) {
      if (c == qc)
        printf("Q");
      else
        printf(".");
    }
    printf("\n");
  }
}

// OK returns true if we can put a queen at (r, c)
inline bool OK(int r, int c) {
  return !col[c] && !down[r - c + N - 1] && !up[r + c];
}

inline void Update(int r, int c) {
  pos[r] = c;
  col[c] = true;
  down[r - c + N - 1] = true;
  up[r + c] = true;
}

inline void Cancel(int r, int c) {
  pos[r] = -1;
  col[c] = false;
  down[r - c + N - 1] = false;
  up[r + c] = false;
}

bool Put(int r) {
  if (r == N)
    return true;
  if (row[r])
    return Put(r + 1);

  for (int c = 0; c < 8; ++c) {
    if (!OK(r, c))
      continue;

    Update(r, c);

    if (Put(r + 1))
      return true;
    else
      Cancel(r, c);
  }
  return false;
}

}  // namespace

int main() {
  int k;
  std::cin >> k;

  for (int i = 0; i < k; ++i) {
    int r, c;
    std::cin >> r >> c;
    Update(r, c);
    row[r] = true;
  }

  if (!Put(0)) {
    std::cerr << "ERROR: not found" << std::endl;
    Print();
    std::exit(1);
  }

  Print();

  return 0;
}

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

int main() {
    int a, b, sum=0;
    cin >> a >> b;

    if (a > b) {
        sum += a;
        a--;
    } else {
        sum += b;
        b--;
    }
    if (a > b) {
        sum += a;
    } else {
        sum += b;
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] A = new int[3][3];
        boolean[][] flag = new boolean[3][3];
        for (int i=0;i<3;i++) {
            for (int j=0;j<3;j++) {
                A[i][j] = sc.nextInt();
            }
        }
        int N = sc.nextInt();
        for (int i=0;i<N;i++) {
            int b = sc.nextInt();
            for (int j=0;j<3;j++) {
                for (int k=0;k<3;k++) {
                    if (A[j][k]==b) flag[j][k]=true;
                }
            }
        }

        boolean ans = false;
        if (flag[0][0] && flag[1][0] && flag[2][0]) ans=true;
        if (flag[0][1] && flag[1][1] && flag[2][1]) ans=true;
        if (flag[0][2] && flag[1][2] && flag[2][2]) ans=true;
        if (flag[0][0] && flag[0][1] && flag[0][2]) ans=true;
        if (flag[1][0] && flag[1][1] && flag[1][2]) ans=true;
        if (flag[2][0] && flag[2][1] && flag[2][2]) ans=true;
        if (flag[0][0] && flag[1][1] && flag[2][2]) ans=true;
        if (flag[2][0] && flag[1][1] && flag[0][2]) ans=true;

        if (ans) System.out.println("Yes");
        else System.out.println("No");
    }
}

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

using namespace std;

int H, R, U, M, S, DU, DM, DS;
int HouseX[100], HouseY[100];
int UmeX[100], UmeY[100];
int MomoX[100], MomoY[100];
int SakuraX[100], SakuraY[100];
int WindD[100], WindR[100];
int Days[100];

const double PI = 3.1415926;


bool isReachHouse(int x0, int y0, int x1, int y1, int d, int w, int a) {
	double len, degree;

	len = sqrt(pow((x1 - x0), 2) + pow((y1 - y0), 2));
	if (len > a) {
		return false;
	}
	degree = atan2((y1 - y0), (x1 - x0)) * 180 / PI;
	//cout << "degree=" << degree << endl;
	if (w - d / 2 <= degree && degree <= w + d / 2) {
		return true;
	}

	degree += 360;
	if (w - d / 2 <= degree && degree <= w + d / 2) {
		return true;
	}
	return false;
}

void solve() {
	int max;
	bool flag;

	for (int i = 0; i < R; ++i) {
		for (int j = 0; j < H; ++j) {
			if (!isReachHouse(0, 0, HouseX[j], HouseY[j], DU, WindD[i], WindR[i])) {
				continue;
			}

			flag = false;
			for (int k = 0; k < U; ++k) {
				if (isReachHouse(UmeX[k], UmeY[k], HouseX[j], HouseY[j], DU, WindD[i], WindR[i])) {
					flag = true;
					break;
				}
			}
			if (flag) {
				continue;
			}

			for (int k = 0; k < M; ++k) {
				if (isReachHouse(MomoX[k], MomoY[k], HouseX[j], HouseY[j], DM, WindD[i], WindR[i])) {
					flag = true;
					break;
				}
			}
			if (flag) {
				continue;
			}

			for (int k = 0; k < S; ++k) {
				if (isReachHouse(SakuraX[k], SakuraY[k], HouseX[j], HouseY[j], DS, WindD[i], WindR[i])) {
					flag = true;
					break;
				}
			}
			if (flag) {
				continue;
			}
			++Days[j];
		}
	}

	max = Days[0];
	for (int i = 1; i < H; ++i) {
		if (Days[i] > max) {
			max = Days[i];
		}
	}

	if (max == 0) {
		cout << "NA" << endl;
		return;
	}

	flag = false;
	for (int i = 0; i < H; ++i) {
		if (Days[i] == max) {
			if (flag) {
				cout << " ";
			}
			cout << i+1;
			flag = true;
		}
	}
	cout << endl;
}

void InputData() {
	for (int i = 0; i < H; ++i) {
		cin >> HouseX[i] >> HouseY[i];
	}
	
	cin >> U >> M >> S >> DU >> DM >> DS;
	
	for (int i = 0; i < U; ++i) {
		cin >> UmeX[i] >> UmeY[i];
	}

	for (int i = 0; i < M; ++i) {
		cin >> MomoX[i] >> MomoY[i];
	}

	for (int i = 0; i < S; ++i) {
		cin >> SakuraX[i] >> SakuraY[i];
	}

	for (int i = 0; i < R; ++i) {
		cin >> WindD[i] >> WindR[i];
	}

	//show
#if 0
	for (int i = 0; i < H; ++i) {
		cout << HouseX[i] << " " << HouseY[i] << endl;
	}
	cout << U << " " << M << " " << S << " " << DU << " " << DM << " " << DS << endl;
	for (int i = 0; i < U; ++i) {
		cout << UmeX[i] << " " << UmeY[i] << endl;
	}
	for (int i = 0; i < M; ++i) {
		cout << MomoX[i] << " " << MomoY[i] << endl;
	}
	for (int i = 0; i < S; ++i) {
		cout << SakuraX[i] << " " << SakuraY[i] << endl;
	}
	for (int i = 0; i < R; ++i) {
		cout << WindD[i] << " " << WindR[i] << endl;
	}
#endif
}

int main() {
	
	while (cin >> H >> R, H) {
		memset(Days, 0, sizeof(Days));
		InputData();
		solve();
	}
	
	return 0;
}



Measured memory_bytes: 3344
D = 10**9+7
N, M = list(map(int,raw_input().split()))
S = list(map(int,raw_input().split()))
T = list(map(int,raw_input().split()))
a = [[0 for j in xrange(M+1)] for i in xrange(N+1)]
for i in xrange(N+1):
  a[i][0] = 1
for j in xrange(M+1):
  a[0][j] = 1
for i in xrange(N):
  for j in xrange(M):
    a[i+1][j+1] = (a[i][j+1]+a[i+1][j])%D
    if S[i]!=T[j]:
      a[i+1][j+1] = (a[i+1][j+1]-a[i][j])%D
print(a[N][M])

Measured memory_bytes: 58908
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int x = sc.nextInt();
	int y = sc.nextInt();
	int z = sc.nextInt();
	x -= z;
	int cout = 0;
	while(x - (y + z) >= 0) {
		cout++;
		x -= y + z;
	}
	System.out.println(cout);
}
}

Measured memory_bytes: 23252
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	if !sc.Scan() {
		panic("failed scan string")
	}
	return sc.Text()
}

func nextInt() int {
	if !sc.Scan() {
		panic("failed scan int")
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

	s := nextString()

	ok := true

	count := 0

	for i, c := range s {
		if i == 0 {
			if c != 'A' {
				ok = false
				break
			}
		} else if i >= 2 && i <= len(s)-2 {
			if c == 'C' {
				count++
			} else if 'a' <= c && c <= 'z' {
			} else {
				ok = false
				break
			}
		} else {
			if 'a' <= c && c <= 'z' {
			} else {
				ok = false
				break
			}
		}
	}
	if ok && count == 1 {
		fmt.Println("AC")
	} else {
		fmt.Println("WA")
	}
}


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

signed main(void){
    int a,b; cin >> a >> b;
    for (int i=1;i<=3;i++){
        if(i!=a && i !=b){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
#define ll long long
const int mod = 1e9+7;
using namespace std;
map<int,int>m;
void fcount(ll x){
  ll i=2;
  while(x>1){
    if(x%i==0){
      while(x%i==0){
        m[i]++;
        x/=i;
      }
    }
    i++;
  }//cout<<"1"<<endl;
}
ll shu(){
  ll ans=1;
  map<int,int>::iterator it;
  for(it = m.begin();it!=m.end();++it){
    //cout<<(*it).first<<' '<<(*it).second<<endl;
    ans=(ans%mod*((*it).second+1))%mod;
  }
  return ans;
}
int main(){
  int n;
  ll sum=1,ans=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    fcount(i);
  }
  //cout<<sum<<endl;
  cout<<shu()<<endl;
  return 0;
}


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

const int N = 100054;

int n, cyc_p = 0, cyc_q = 0;
int p[N], q[N], bp[N], bq[N];

namespace F {
	#define ad(x) ((x - 1 ^ 1) + 1)

	const int N = ::N * 2, M = ::N * 4;

	struct edge {
		int u, v, f;
		edge (int u0 = 0, int v0 = 0, int f0 = 0) : u(u0), v(v0), f(f0) {}
	} e[M];

	int V = 2, E = 0, si = 1, ti = 2, flow;
	int first[N], next[M];
	int dep[N], cur[N], que[N];

	inline void addedge(int u, int v, int f) {
		e[++E] = edge(u, v, f), next[E] = first[u], first[u] = E;
		e[++E] = edge(v, u), next[E] = first[v], first[v] = E;
	}

	bool bfs() {
		int h, t = 1, i, x, y;
		memset(dep, -1, sizeof dep);
		que[0] = si, dep[si] = 0;
		for (h = 0; h < t; h++) {
			if ((x = que[h]) == ti) return true;
			for (i = first[x]; i; i = next[i])
				if (dep[y = e[i].v] == -1 && e[i].f)
					que[t++] = y, dep[y] = dep[x] + 1;
		}
		return false;
	}

	int dfs(int x, int lim) {
		int a, c, f = 0;
		if (x == ti || !lim) return lim;
		for (int &i = cur[x]; i; i = next[i])
			if (dep[e[i].v] == dep[x] + 1 && e[i].f) {
				a = std::min(lim - f, e[i].f);
				c = dfs(e[i].v, a);
				e[i].f -= c; e[ad(i)].f += c;
				if ((f += c) == lim) return f;
			}
		return f;
	}

	int Dinic() {
		for (flow = 0; bfs(); flow += dfs(si, INT_MAX))
			memcpy(cur, first, sizeof cur);
		return flow;
	}
}

int main() {
	int i, j, ans;
	scanf("%d", &n), ans = n;
	for (i = 0; i < n; ++i) scanf("%d", p + i);
	for (i = 0; i < n; ++i) scanf("%d", q + i);
	for (i = 0; i < n; ++i) if (!bp[i]) for (++cyc_p, j = i; !bp[j]; j = p[j]) bp[j] = cyc_p;
	for (i = 0; i < n; ++i) if (!bq[i]) for (++cyc_q, j = i; !bq[j]; j = q[j]) bq[j] = cyc_q;
	for (i = 0; i < n; ++i)
		switch ((p[i] == i) | (q[i] == i) << 1) {
			case 0: F::addedge(2 + bp[i], 2 + cyc_p + bq[i], 1);
				if (p[i] == q[i]) F::addedge(2 + cyc_p + bq[i], 2 + bp[i], 1);
				break;
			case 1: F::addedge(1, 2 + cyc_p + bq[i], 1); break;
			case 2: F::addedge(2 + bp[i], 2, 1); break;
			case 3: --ans; break;
		}
	printf("%d\n", ans - F::Dinic());
	return 0;
}

Measured memory_bytes: 12800
#setの対称差を用いた方法
S = set(input()) #list()と同じで,set()も一発で行ける！
lists = set([chr(i) for i in range(ord('a'), ord('z')+1)])
ans = lists^S
print(min(ans) if len(list(ans)) != 0 else 'None')

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<cstdio>
#include<cctype>
#include<vector>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>
#include<unordered_map>
#include<stack>
#include<map>
#include<bitset>
#include <cstdlib>
#include<cstring>
#define ll long long;
#define pb push_back
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
using namespace std;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);

	int a, b, c;
	cin >> a >> b >> c;
	int flag = 0;
	for (int i = b; i <= c; i++)
	{
		if (i % a == 0)
		{
			flag = 1;
			break;
		}
	}
	if (flag == 0)
		cout << "NG";
	else cout << "OK";

	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N,M;
  cin >> N >> M;
  int A[M];
  int sum = 0;
  for (int i = 0; i < M; i++) {
    cin >> A[i];
    sum += A[i];
  }
  int ans = -1;
  if (sum > N) {
    ans = -1;
  }
  else {
    ans = N - sum;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	string s;
	cin >> s;
	if(s[0]=='7' || s[1]=='7' ||s[2]=='7')
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 3636
#include <stdio.h>

int main() {
char a;
char ch[120];
char c[120];
char b[120];
int i,j,k,l,m,n,o;
m = 0;
n = 0;
i=0;
l=0;

while(1) {
scanf("%c",&a);

if(a == '\n') {
 break;
}

ch[i] = a;
i=i+1;

}

j=0;
while(1) {
scanf("%c",&a);
if(a == '\n') {
break;
}
c[j] = a;
j +=1;
}
/*??????????????§??\??????*/

for(k=0;k<i;k++) {

if(c[0] == ch[k] ) {       /*???????????????????????¨?????????????????? */
 l = k;
n = 0;                         /* ??????????????´???????????????*/
for(m=0;m<i-k;m++) {         /* c[k]????????????????§????????????? */
n = n +1;
l  +=1;
b[m] = ch[l-1];
}
l=0;
for(m=n;m<n+1+k;m++) {
l +=1;
b[m] = ch[l-1];            
}
o=0;
for(n=0;n<j;n++) {
/*printf("b[%d] = %c\n c[%d] = %c\n",n,b[n],n,c[n]); */
if(b[n] == c[n]){
o +=1;
}
}
}

/* printf("i = %d\nj = %d\n",i,j); */


if(o == j) {
printf("Yes\n");
break;
} else if(k==i-1) {
printf("No\n");
}
}
 
return 0;

}



Measured memory_bytes: 2144
using System;
using System.Collections.Generic;

class Program
{
 static void Main(string[] args)
 {
   int total = int.Parse(Console.ReadLine());
   string[] numStrArray = Console.ReadLine().Split(' ');
   int[] numArray = new int[total];
   int cnt = 0;
   int buff;
   bool no_error = true;
   List<int> listValue = new List<int>();
   
   for( cnt = 0; cnt < total; cnt++ )
   {
     buff = int.Parse(numStrArray[cnt]);
     numArray[cnt] = buff;
     
     if( buff > (cnt+1) )
     {
       no_error = false;
       break;
     }
   }

   if(no_error)
   {
     for( cnt = 0; cnt < total; cnt++ )
     {
       if( cnt == 0 )
       {
          listValue.Add(numArray[cnt]);
       }
       else
       {  
         buff = (listValue.Count - (numArray[cnt] - 1));
         if( buff == listValue.Count)
         {
          listValue.Add(numArray[cnt]);
         }
         else
         {
           listValue.Insert(buff, numArray[cnt]);
         }
       }
     } 
   }
   
   if(no_error)
   {
     listValue.Reverse();
     foreach( int i in listValue )
     {
       Console.WriteLine(i);
     }
   }
   else
   {
     Console.WriteLine(-1);
   }
 }
}

Measured memory_bytes: 13268
def main():
  n,m,x = [int(x) for x in input().split()]
  c = []
  a = []
  for i in range(n):
    tmp = [int(x) for x in input().split()]
    c.append(tmp[0])
    a.append(tmp[1:])
  #print(n, m, x)
  #print(c)
  #print(a)
  
  def check(b):
    p = b
    y = [0]*m
    z = 0
    for i in range(n):
      if p % 2 == 1:
        #print(i, end=",")
        for j in range(m):
          y[j] += a[i][j]
        z += c[i]
      p = p >> 1
    #print("value =", z)
    for j in range(m):
      if y[j] < x:
        return False, -1
    return True, z
      
  minx = None
  for b in range(2**n):
    #print(b)
    flg, val = check(b)
    if flg:
      minx = val if minx is None else min(val, minx) 
  print(-1 if minx is None else minx)
main()

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

int main(){
	int N, L;
	cin >> N >> L;
	vector<string> SS;
	for(int i=0; i<N; ++i){
		string S;
		cin >> S;
		SS.emplace_back(S);
		sort(SS.begin(),SS.end());
	}

	for(auto S:SS) cout << S;
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a*c>=a*d){
    if(a*c>=b*c&&a*c>=b*d){
      cout<<a*c<<endl;
    }
    else if(a*c<b*c||a*c<b*d){
      if(b*c>b*d){
        cout<<b*c<<endl;
      }
      else{
        cout<<b*d<<endl;
      }
    }
  }
  else{
    if(a*d>=b*c&&a*d>=b*d){
      cout<<a*d<<endl;
    }
    else if(a*d<b*c||a*d<b*d){
      if(b*c>b*d){
        cout<<b*c<<endl;
      }
      else{
        cout<<b*d<<endl;
      }
    }

  }
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
long long  a,arr[100010],brr[100010],tmp1,tmp2,tmp3;
void input(){
    cin>>a;
    for (int i=0;i<a;i++){
        cin>>arr[i];
        if (arr[i]%4==0)
            tmp1++;
        if (arr[i]%2==1)
            tmp2++;
        if (arr[i]%2==0)
            tmp3++;
    }
}
void solve(){
    tmp3-=tmp1;
    if (tmp3%2==1)
        tmp3=tmp3-(tmp3-1);
    if (tmp2-tmp1<=1&&tmp3%2==0)
        cout<<"Yes";
    else if ((tmp2+tmp3)-tmp1<=1)
        cout<<"Yes";
    else
        cout<<"No";
}
int main(){
    input(),solve();
}


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

words = [input() for i in range(0, n)]

shiritori = []

def solve():
  last_char = words[0][0]
  for i in range(0, n):
    # 既に使った単語があるとダメ
    if words[i] in shiritori:
      print('No')
      return
    
    # 前の単語の末尾の文字と今の単語の先頭の文字が不一致だとダメ
    if words[i][0] != last_char:
      print('No')
      return

    last_char = words[i][len(words[i])-1]
    shiritori.append(words[i])

  print('Yes')


def main():
  solve()


if __name__ == "__main__":
  main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
int fg(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
signed main(){
 int k;
 cin>>k;
 double n=100;
 for(int i=0;i<INF;i++){
  n=floor(n*1.01);
   if(n>=k){
     cout<<i+1;
     break;
   }
 }
}


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

int main()
{
	int H, W;

	while (true) {
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		for (int i = 0; i < H; i++)
		{
		for (int j = 0; j < W; j++)
			cout << "#";
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

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


int main()
{
  ll l, r;
  cin >> l >> r;
  r = min(r, l + 2018);
  ll ans = 2019;
  for (ll i=l; i<r; i++)
    for (ll j=i+1; j<=r; j++)
      ans = min(ans, i * j % 2019);
  cout << ans << endl;
  return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

int main() {

    ll n;
    cin >> n;
    map<string, int> strs;

    ll ans = 0;
    rep(i, n) {
        string str;
        cin >> str;
        sort(str.begin(), str.end());

        if (strs.find(str) == strs.end()) {
            strs[str] = 1;
        } else {
            strs[str]++;
        }
    }

    for (auto itr = strs.begin(); itr != strs.end(); ++itr) {
        ll value = itr->second;
        ans += value * (value - 1) / 2;
    }

    cout << ans << endl;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int a, b, k;
    cin >> a >> b >> k;

    for(int in=a;in<=b;in++) {
        if(in<=a+k-1||b-k+1<=in) cout << in << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,k = LI()
a = LI()
check = [-1]*n
cntr = 0
que = deque([0])
while que:
    x = que.popleft()
    if check[x] != -1:
        break
    check[x] = cntr
    cntr += 1
    que.append(a[x]-1)
c = check[x]
if k < cntr:
    for i in range(n):
        if check[i] == k % cntr:
            print(i+1)
            quit()
    
check = [-1]*n
cntr = 0
que = deque([x])
while que:
    x = que.popleft()
    if check[x] != -1:
        break
    check[x] = cntr
    cntr += 1
    que.append(a[x]-1)

for i in range(n):
    if check[i] == (k-c) % cntr:
        print(i+1)

Measured memory_bytes: 90152
package main

import (
	"fmt"
)

func main()  {
	var n int

	fmt.Scan(&n)
	a := make([]int64, n)

	for i := range a {
		fmt.Scan(&a[i])
	}

	x :=  a[0]
	for i:=1;i<n;i++ {
		x = gcd(x, a[i])
		//fmt.Println(x)
	}

	fmt.Println(x)
}

func gcd(x int64, y int64) int64 {
	if x < y {
		x, y = y, x
	}
	//fmt.Println(x, y)
	z := x%y
	x =  x/y
	//fmt.Printf("%d %d %d\n",x, z, y)

	if z == 0 {
		return y
	} else {
		return gcd(y, z)
	}
}

Measured memory_bytes: 5504
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
ll gcd(ll x,ll y){
	if(y==0)return x;
	return gcd(y,x%y);
}
ll absol(ll x)
{
	if (x<0)
	{
		return -x;
	}
	return x;
}
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
ll expo(ll b,ll n,ll m)
{
 ll r,p;
	p=1;
	 b=b%m;
	while(n>0)
	{ 
		r=n%2;
		if(r==1)
		   p=((p%m)*(b%m))%m;
		b=((b%m)*(b%m))%m; 
		n=n/2;		
	}
 return (p%m);
}
ll divide1(ll a,ll b,ll m)
	{ ll r,p,n;
			p=a%m;
				n=m-2;
				while(n>0){
						 r=n%2;
						if(r==1)
							p=((p%m)*(b%m))%m;
						b=((b%m)*(b%m))%m; 
						n=n/2;	
					}
	return (p%m); }
ll w1[1002],v[1002];
ll dp[100012][101];
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	ll n,w;
	cin>>n>>w;
	for (int i = 0; i < n; ++i)
	{
		cin>>w1[i]>>v[i];
	}
	for(int i=n-1;i>=0;--i)
	{
		for (int j = 0; j <= w; ++j)
		{
			dp[j][i]=dp[j][i+1];
			if (j>=w1[i])
			{
				dp[j][i]=max(dp[j][i],dp[j-w1[i]][i+1]+v[i]);
			}
		}	
	}
	cout<<dp[w][0]<<"\n";
	return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans ^= a[i];
    }
    for(int i = 0; i < n; i++){
        cout << (ans ^ a[i]) << " ";
    }
    return 0;
}

Measured memory_bytes: 4044
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N), cnt(N, 0);
  ll a;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
    cnt[A[i]]++;
  }
  vector<ll> C(N, 0);
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    C[i] = cnt[i] * (cnt[i] - 1) / 2;
    sum += C[i];
  }
  for (int i = 0; i < N; i++) {
    ll res = ((cnt[A[i]] - 1) * (cnt[A[i]] - 2) / 2);
    cout << sum - C[A[i]] + res << endl;
  }
  return 0;
}

Measured memory_bytes: 7296
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s = sc.next();
		//String t = sc.next();
		long n = sc.nextLong();
		long m = sc.nextLong();
		//long k = sc.nextLong();
		//long l = sc.nextLong();
		//long count=0;

		/*for(int i=0;i<3;i++) {
			if(s.substring(i,i+1).equals(s.substring(i+1,i+2))) {
				count++;
			}else if(i!=2){
				count=0;
			}
		}*/
		if((n*m)%2==0) {
			System.out.println("Even");
		}else{
			System.out.println("Odd");
		}
		//System.out.println((int)Math.ceil((n+m)/2.0));
		//System.out.println(s.replace("2017", "2018"));
	}
}




Measured memory_bytes: 21972
N, M = map(int, input().split())

n = list(map(int, input().split()))
sort_n = sorted(n, reverse=True)
t = sum(n)

c = 0

for i in range(0,M):
    if sort_n[c] >= t*(1/(4*M)):
        c += 1
        
    else:
        continue

if c == M:
    print("Yes")
else:
    print('No')


Measured memory_bytes: 3060
#include<iostream>

int a,b;

int Digit(int x){
	int t=10,ans=1;
	for(;x/t > 0; ans++){
		t *= 10;
	}
	return ans;
}

int main(){
	while(std::cin >> a >> b)
		std::cout << Digit(a+b) << std::endl;
	return 0;
}

Measured memory_bytes: 0
//creator :Harjot Singh	

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vi vector<int> 
#define vll vector<long long > 
#define loop(i,a,b) for(int i=a;i<=b;i++)
#define vii vector<vector<int>> 
#define ll long long 

int main()
{
   


      int n;
      cin>>n;
      int top=n/1000;
      if(n%1000!=0)
      	 top+=1;
      	cout<<1000*top-n<<endl;
      	
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>

using namespace std;

int main(){

  unsigned long long a, b;
  int n;
  while(cin >> a >> b >> n){
    unsigned long long sum = 0;
    for(int i = 0; i < n; i++){
      a = a%b;
      a*=10;
      sum += a/b;
    }
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 0
from itertools import permutations


def main():
    n, m = map(int, input().split())
    a = {tuple(int(i) - 1 for i in input().split()) for _ in range(m)}
    c = 0
    for per in permutations(range(1, n)):
        p = [0] + list(per)
        for i in range(n - 1):
            if (p[i], p[i + 1]) not in a and (p[i + 1], p[i]) not in a:
                break
        else:
            c += 1
    print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string s,ss;
ll ar[100009];
ll br[100009];
vector<char>v;
char ch;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll n,ans,res,i,j,c=0,f=0,len1,len2,s=0;
    double a,b;
    cin>>a>>b;s=1;
    for(i=1;;i++){
            if(s>=b)break;
      s=s+a;
      s--;
       c++;
    }
    cout<<c<<endl;
   return 0;

}


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

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const ll inf = (ll)1e9 + 7;
const ll N = (ll)2e5 + 7;

ll n,k;
ll a[N],pr[N],t[N + 1];
ll ans;

vector <ll> v;

ll sum (ll r) {
        ll res = 0;
        for (ll i = r; i > 0; i -= i & (-i))
                res += t[i];
        return res;
}
void update (ll pos,ll val) {
        for (ll i = pos; i <= N; i += i & (-i)) {
                t[i] += val;
        }
}
main () {
        scanf("%lld%lld", &n,&k);

        for (ll i = 1; i <= n; i ++) {
                scanf ("%lld", &a[i]);

                a[i] -= k;
                pr[i] = pr[i - 1] + a[i];
                v.pb(pr[i]);
        }
        pr[0] = 0;
        v.pb(pr[0]);

        sort(v.begin(),v.end());
        unique(v.begin(),v.end());

        for (ll i = 0; i <= n; i ++) {
                pr[i] = lower_bound(v.begin(),v.end(),pr[i]) - v.begin() + 1;
        }
        for (ll i = 0; i <= n; i ++) {
                ans += sum(pr[i]);
                update(pr[i],1);
        }
        cout << ans << endl;
}



Measured memory_bytes: 6640
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define debug(n) cout<<"# "<<#n<<": "<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	vi a;
	for(int n;cin>>n;)
		a.push_back(n);
	
	vi hist(101);
	rep(i,a.size())
		hist[a[i]]++;
	
	int mode_count=*max_element(allof(hist));
	rep(i,hist.size())
		if(hist[i]==mode_count)
			cout<<i<<endl;
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define MAX 200000

long long fac[MAX], finv[MAX], inv[MAX];

//テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

//二項係数計算
long long COM(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    COMinit();
    ll ans = 0;
    for(int i = b; i < w; i++){
        ans += COM(h - a - 1 + i, i) * COM(a - 1 + w - i - 1, w - i - 1);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  unsigned N;
  std::cin >> N;
  std::vector<std::pair<unsigned, unsigned>> x(N);
  std::vector<bool> used(N * N + 1, false);
  std::vector<unsigned> ans(N * N + 1);
  for (unsigned i = 0; i < N; ++i) {
    std::cin >> x[i].first;
    x[i].second = i + 1;
  }
  std::sort(x.begin(),
            x.end(),
            [](std::pair<unsigned, unsigned> i, std::pair<unsigned, unsigned> j) -> bool { return i.first < j.first; });
  for (const auto &i : x) {
    used[i.first] = true;
    ans[i.first] = i.second;
  }
  unsigned index = 1u;
  for (unsigned i = 0; i < N; ++i) {
    unsigned cnt = x[i].second - 1;
    for (unsigned j = index; cnt > 0u; ++j) {
      if (used[j]) continue;
      ans[j] = x[i].second;
      --cnt;
      if (cnt == 0u) {
        index = j + 1;
        break;
      }
    }
    if (index > x[i].first) {
      std::cout << "No";
      return 0;
    }
  }
  index = N * N;
  for (unsigned i = N; i-- > 0;) {
    unsigned cnt = N - x[i].second;
    for (unsigned j = index; cnt > 0u; --j) {
      if (used[j]) continue;
      ans[j] = x[i].second;
      --cnt;
      if (cnt == 0u) {
        index = j - 1;
        break;
      }
    }
    if (index < x[i].first) {
      std::cout << "No";
      return 0;
    }
  }
  std::cout << "Yes" << std::endl;
  for (unsigned i = 1; i < N * N; ++i) {
    std::cout << ans[i] << " ";
  }
  std::cout << ans[N * N];
  return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int[] A = new int[n];
			for(int i=0;i<n;i++){
				A[i] = sc.nextInt();
			}
			int q = sc.nextInt();

            int[] buf = A.clone();
			for(int i=0;i<q;i++) {
				int b = sc.nextInt();
				int m = sc.nextInt();
				int e = sc.nextInt();
				for(int k=(e-b-1);k>=0;k--) {
					buf[b+((k+(e-m))%(e-b))] = A[b+k];
				}
				A = buf.clone();
			}
			System.out.print(A[0]);
			for(int i=1;i<A.length;i++) {
				System.out.print(" " + A[i]);
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 41548
m,n=[int(x) for x in input().split()]
connections=[[] for i in range(m+1)]
for i in range(n):
	a,b=[int(x) for x in input().split()]
	connections[a].append(b)
	connections[b].append(a)
for i in range(1,m+1):
	print(len(connections[i]))

Measured memory_bytes: 62348
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#define MAX_N   1000+10

using namespace std;
const int INF=1000000;
typedef pair<int,int> P;
int H,W,N,d[MAX_N][MAX_N];
char Map[MAX_N][MAX_N];
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
int sx,sy,gx,gy,power,ans;

int bfs(char c)
{
    queue<P> que;
    for(int i=0;i<H;i++)
        for(int j=0;j<W;j++)
            d[i][j]=INF;
    que.push(P(sx,sy));
    d[sx][sy]=0;
    P p;
    while(que.size())
    {
        p=que.front();
        que.pop();
        if(Map[p.first][p.second]==c)
        {
            sx=p.first;
            sy=p.second;
            break;
        }
        for(int i=0;i<4;i++)
        {
            int nx=p.first+dx[i];
            int ny=p.second+dy[i];
            if(nx>=0&&nx<H&&ny>=0&&ny<W&&Map[nx][ny]!='X'&&d[nx][ny]==INF)
            {
                que.push(P(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }
    return d[sx][sy];
}
int main()
{
    while(cin>>H>>W>>N)
    {
        ans=0;
        for(int i=0;i<H;i++)
        {
            for(int j=0;j<W;j++)
            {
                cin>>Map[i][j];
                if(Map[i][j]=='S')
                {
                    sx=i;
                    sy=j;
                    Map[i][j]='.';
                }
            }
        }
        for(int i=1;i<=N;i++)
        {
            ans+=bfs(i+48);
        }
        cout<<ans<<endl;
    }
}

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

constexpr ll INF = 1e18;
constexpr int N = 1000010;

ll dp[N][2];

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

  reverse(s.begin(), s.end());
  s += '0';

  for (int i = 0; i < N; i++) for (int j = 0; j < 2; j++) dp[i][j] = INF;

  int n = s.size();

  // 0 : 繰りさがりなし 1 : 繰りさがりあり
  dp[0][0] = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      int x = s[i] - '0';
      x += j;

      for (int a = 0; a <= 9; a++) {
       int ni = i + 1;
       int nj = 0;

       int b = a - x;
       if(b < 0) {
         nj = 1;
         b += 10;
       }

       dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b);
      }
    }
  }

  cout << dp[n][0] << '\n';
}

Measured memory_bytes: 17028
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <cstdio>
#include <iomanip>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;(i)>=0;(i)--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;


void rec(vector<int> a,int t){
    if(a.size()==0||a[a.size()-1]>=t){
        REP(i,a.size())cout<<a[i]<<" ";
        cout<<t<<endl;
    }
    if(t>1){
        for(int i=1;i<=t-1;i++){
            int n=t-i;
            vector<int> at=a;
            if(at.size()==0){
                at.push_back(n);
                rec(at,i);
            }else{
                if(at[at.size()-1]>=n){
                    at.push_back(n);
                    rec(at,i);
                }
            }
        }
    }
}


int main(){

    while(true){
        int n;
        cin>>n;
        if(n==0)break;
        
        vector<int> t;
        rec(t,n);
        
    }
    
    return 0;
}

Measured memory_bytes: 3100
N=int(input())
L=[int(i) for i in input().split()]
ma=max(L)
sum_=0
ma_index=L.index(ma)
for i in range(N):
  if i!=ma_index:
    sum_=sum_+L[i]
  else:
    pass
if ma<sum_:
  print("Yes")
else:
  print("No")
    

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
#define MAX 100000

int main()
{
	int a, b, c, d;
	int total;
	cin >> a >> b >> c >> d;

	if (a <= c && b>=c)
	{
		if (d <= b)
			total = d - c;
		else
			total = b - c;
	}
	else if (c > b)
	{
		cout << "0";
		return 0;
	}

	else if (a >= c && a <= d)
	{
		if (b <= d)
		{
			total = b - a;
		}
		else
			total = d - a;
	}

	else if (a > d)
	{
		cout << "0";
		return 0;
	}

	else
	{
		total = b - a;
	}



	cout << total;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	long long a,v,b,w,t;
	cin>>a>>v;
	cin>>b>>w;
	cin>>t;
	if(a<0&&b<0){
		a=-a;
		b=-b;
	}
	if(a+t*v<b+t*w||a-t*v>b-t*w)
		cout<<"NO";
	else
		cout<<"YES";
	return 0;
}


Measured memory_bytes: 3688
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
s = rr()
cnt = 0
i = 0
j = n-1
while True:
    while s[i] == 'R':
        i += 1
        if i >= n:
            break
    while s[j] == 'W':
        j -= 1
        if j < 0:
            break
    if i < j:
        cnt += 1
        i += 1
        j -=1
    else:
        break
print(cnt)


Measured memory_bytes: 27292
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define tcase int _; cin >> _; while(_--)
const int MAX = 1e6;

string s;

void solve() {
	cin >> s;
	int ans = 0, n = s.size();
	for(int i=0; i<n/2; i++) if(s[i] != s[n-i-1]) ans++;
	cout << ans;
}

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

 	solve();

  	return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define oo 0x3f3f3f3f

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,m,k;
    cin>>n>>m>>k;
    vector<string>A(n);
    for(auto&s:A)cin>>s;

    int res = 0;

    for(int i=0; i<(1<<n); i++)
    for(int j=0; j<(1<<m); j++)
    {
        int cnt = 0;
        bitset<8>r(i),c(j);
        for(int ii=0; ii<n; ii++)
            if(!r[ii])
        for(int jj=0; jj<m; jj++)
            cnt+=A[ii][jj]=='#' && !c[jj];
        res+=cnt==k;
    }

    cout<<res;
}


Measured memory_bytes: 3644
n = int(input())
a, b = map(int, input().split())
p = sorted([int(i) for i in input().split()])

gte_a = len(p)
for i,v in enumerate(p):
    if a + 1 <= v <= b:
        gte_a = i
        break

gte_b = len(p)

for i,v in enumerate(p):
    if b + 1 <= v:
        gte_b = i
        break

s = range(0, gte_a)
t = range(gte_a, gte_b)
u = range(gte_b, len(p))
print(min(map(len, (s,t,u))))

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]

def main():
    N, M, X = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(N)]

    inf = 10**18

    # bit全探索
    # repeat=2だと(0,0), (0,1), (1,0), (1,1)になる
    ans = inf
    for i in product([0,1], repeat=N):
        ok = True
        for m in range(1, M + 1):
            s = 0
            for n in range(N):
                if i[n] == 1:
                    s += A[n][m]
            if s < X:
                ok = False
                break
        if ok:
            money = 0
            for n in range(N):
                if i[n] == 1:
                    money += A[n][0]
            ans = min(ans, money)

    if ans == inf:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 73316
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int[] a = new int[1000000];
		a[1] = 0;
		boolean[] isPrime = new boolean[1000000];
		Arrays.fill(isPrime, true);
		for (int i = 2; i < 1000000; i++) {
			a[i] = a[i - 1];
			if (isPrime[i]) {
				a[i]++;
				for (int j = i * 2; j < 1000000; j += i) {
					isPrime[j] = false;
				}
			}
		}
		
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			int n = in.nextInt();
			System.out.println(a[n]);
		}
	}
}

Measured memory_bytes: 26212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_20190707_1
{    class Program
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();

            int SN = 0;

            for (int i = 0; i < N.Length; i++)
            {
                SN += int.Parse(N[i].ToString());
            }

            if(int.Parse(N) % SN == 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

//#define int long long
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a[100], t;

signed main() {
	cin >> n;
	rep(i,n) cin >> a[i];
	rep(i,n) {
		int mn = i;
		reps(j,i,n) if (a[j]<a[mn]) mn = j;
		swap(a[i], a[mn]);
		t += i!=mn;
	}
	rep(i,n) cout << a[i] << (i==n-1 ? '\n' : ' ');
	cout << t << ln;
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

struct edge{
    int to;
    ll cost;
};

vector<edge> nodes[100000];
ll zahyou[100000];

void init(){
    rep(i, 100000) zahyou[i] = -mod;
}

bool dfs(int p, int s){
    bool ret = true;
    rep(i, nodes[s].size()){
        int to = nodes[s][i].to;
        ll cost = nodes[s][i].cost;
        if(zahyou[to] == -mod){
            zahyou[to] = zahyou[s] + cost;
            ret &= dfs(s, to);
        }
        else{
            if(zahyou[to] != zahyou[s] + cost) ret = false;
        }
    }
    return ret;
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    init();
    int N, M; cin >> N >> M;
    rep(i, M){
        int l, r; ll c;
        cin >> l >> r >> c; l--; r--;
        edge e; e.cost = c; e.to = r;
        nodes[l].push_back(e);
        e.cost *= -1; e.to = l;
        nodes[r].push_back(e);
    }
    bool ok = true;
    rep(i, N){
        if(zahyou[i] == -mod){
            zahyou[i] = 0;
            ok &= dfs(-1, i);
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 17408
h,w = map(int,input().split())
mod = 10**9 + 7
data = [input() for _ in range(h)]
dp = [[0 for _ in range(w)] for i in range(h)]
dp[0][0] = 1
for i in range(h):
    for j in range(w):
        if data[i][j] == '.':
            if i > 0:
                dp[i][j] += dp[i-1][j]
            if j > 0:
                dp[i][j] += dp[i][j-1]
            dp[i][j] %= mod

print(dp[h-1][w-1])

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

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

// ========================================================================= //

const int N = 100179;

int main() {
    ios::sync_with_stdio(false);

    int n;
    string s;
    cin >> n >> s;

    int cnt1 = 0;

    vector < int > nxt0(n+1);
    nxt0[n] = IINF;
    for (int i = n - 1; i >= 0; --i) {
        if (s[i] == '0')
            nxt0[i] = i;
        else {
            nxt0[i] = nxt0[i+1];
            ++cnt1;
        }
    }

    vector < int > d(n+1, IINF);
    d[0] = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '0') {
            d[i+1] = min(d[i+1], d[i]);
        } else {
            d[i+1] = min(d[i+1], d[i] + 1);
            int x = nxt0[i];
            if (x + 1 < n && s[x+1] == '1')
                d[x+2] = min(d[x+2], d[i] + 1);
            if (i + 2 < n && s[i+1] == '0' && s[i+2] == '1') {
                int x = min(n, nxt0[i+2]);
                for (int j = x; j >= max(i+3, x-5); --j)
                    d[j] = min(d[j], d[i]+1);
                if (x + 1 < n && s[x+1] == '0')
                    d[x+2] = min(d[x+2], d[i] + 1);
            }
        }
    }

    cout << cnt1 - d[n] << "\n";

    return 0;
}


Measured memory_bytes: 4764
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

ll floor_sum(ll n,ll m,ll a,ll b){
  ll ans=0;
  ans+=(n-1)*n*(a/m)/2+n*(b/m);
  a%=m;
  b%=m;

  ll y_max=(a*n+b)/m, x_max=(y_max*m-b);
  if(y_max==0) return ans;
  ans+=(n-(x_max+a-1)/a)*y_max;
  ans+=floor_sum(y_max,a,m,(a-x_max%a)%a);
  return ans;
}

int main(){
  int t;
  cin>>t;
  
  rep(i,t){
    int n,m,a,b;
    cin>>n>>m>>a>>b;  
    cout<<floor_sum(n,m,a,b)<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		int a = Integer.parseInt(scanner.nextLine());
		String s = scanner.nextLine();
		if (a >= 3200) {
			System.out.println(s);
		} else {
			System.out.println("red");
		}
	}
}

Measured memory_bytes: 23252