akhauriyash/Code-Regression huggingface dataset:
def answer(*inp):

    _in = inp[0].split()
    N = int(_in[0])
    A = int(_in[1])
    B = int(_in[2])

    total = 0

    for n in range(N):
        _sum = 0
        for i in str(n + 1):
            _sum += int(i)

        if A <= _sum <= B:
            total += (n + 1)

    print(total)

answer(input())

Measured memory_bytes: 3064
A, B, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

small = min(a) + min(b)

for i in range(m):
    x, y, c = map(int, input().split())
    small = min(small, a[x - 1] + b[y - 1] - c)

print(small) 

Measured memory_bytes: 18612
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U> bool chmax(T &a, U b) { if (a <= b) {a = b; return 1;} return 0; }
template <class T, class U>  bool chmin(T &a, U b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T>  ostream &operator<<(ostream &os, vector<T> &v) { os << "{"; rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); } os << "}"; return os; }

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

int main() {
    ll x=0,y=0,z=0,n,m,ans=0,sum=0,k,w,Max=-1,Min=1e9+1;
    bool ok = true;
    string t,u;
    VS s(3);
    cin >> s[0] >> s[1] >> s[2];

    while(1){
      if(s[x].size() == 0){
        cout << (char)(x + 'A') << endl;
        return 0;
      }
      char c = s[x][0];
      //s[x].erase(s[x].begin());
      s[x] = s[x].substr(1,s[x].size()-1);
      x = c-'a';
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
using namespace std;

typedef long long ll;

int main() {
	int N, C; cin >> N >> C;
	vector<vector<int>> D(C + 2, vector<int>(C + 2)), c(N + 2, vector<int>(N + 2));
	for (int i = 1; i <= C; i++) {
		for (int j = 1; j <= C; j++) {
			cin >> D[i][j];
		}
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			cin >> c[i][j];
		}
	}
	vector<vector<int>> s(3, vector<int>(C + 2, 0));
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			for (int k = 1; k <= C; k++) {
				s[(i + j) % 3][k] += D[c[i][j]][k];
			}
		}
	}
	int ans = 1e9;
	for (int i = 1; i <= C; i++) {
		for (int j = 1; j <= C; j++) {
			for (int k = 1; k <= C; k++) {
				if (i == j || j == k || k == i) continue;
				ans = min(ans, s[0][i] + s[1][j] + s[2][k]);
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1280
from itertools import combinations

n = int(input())
l = sorted(map(int, input().split()))
c = 0
for i, j, k in combinations(range(n), 3):
    li, lj, lk = l[i], l[j], l[k]
    if li == lj or lj == lk or lk == li:
        continue
    if li + lj > lk:
        c += 1
print(c)


Measured memory_bytes: 9180
/*
 *created by Kraken on 28-03-2020 at 17:05
 */
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int k = sc.nextInt(), n = sc.nextInt();
		int[] x = new int[n];
		for (int i = 0; i < n; i++) x[i] = sc.nextInt();
		long maxdiff = (k - x[n - 1]) + x[0];
		for (int i = 1; i < n; i++) maxdiff = Math.max(maxdiff, x[i] - x[i - 1]);
		System.out.println(k - maxdiff);
	}

	static class FastReader {

		BufferedReader br;

		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			}
			catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 49744
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
using namespace std;

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=2019;
#define ll long long
int a[114514];
int main(){
    int a;
    string s;
    cin>>a;
    cin>>s;
    if(a>=3200){
        cout<<s<<endl;
    }
    else{
        cout<<"red"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n, m, x;
llint c[15];
llint a[15][15];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> x;
	for(int i = 0; i < n; i++){
		cin >> c[i];
		for(int j = 1; j <= m; j++){
			cin >> a[i][j];
		}
	}
	
	llint N = 1<<n, ans = inf, sum[15], cost;
	for(int i = 0; i < N; i++){
		cost = 0;
		for(int j = 1; j <= m; j++) sum[j] = 0;
		for(int j = 0; j < n; j++){
			if(!(i & (1<<j))) continue;
			cost += c[j];
			for(int k = 1; k <= m; k++) sum[k] += a[j][k];
		}
		bool flag = true;
		for(int j = 1; j <= m; j++){
			if(sum[j] < x) flag = false;
		}
		if(flag) ans = min(ans, cost);
	}
	if(ans > inf/2) cout << -1 << endl;
	else cout << ans << endl;
	
	return 0;
}

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

void solve(long double A, long double B, long double H, long double M)
{
    double tyo = (H / 12 + M / 60 / 12) * 2 * M_PI;
    double tan = M / 60 * 2 * M_PI;
    double ans = A * A + B * B - 2 * A * B * cos((tyo - tan));
    ans = sqrt(ans);
    printf("%.10lf\n", ans);
}

signed main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long H;
    scanf("%lld", &H);
    long long M;
    scanf("%lld", &M);
    solve(A, B, H, M);
    return 0;
}


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

using namespace std;

main(){
    string str;
    int arr[26];
    for(int i=0;i<26;++i) arr[i] = 0;
    cin >> str;
    for(int i=0;i<str.size();++i){
        arr[str[i]-'a'] += 1;
    }
    bool all = true;
    char ans;
    for(int i=0;i<26;++i){
        if(arr[i]==0){
            all = false;
            ans = i+'a';
            break;
        }
    }
    if(all) cout << "None" << endl;
    else cout << ans << endl;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  ld r;
  cin >> r;
  const ld pi = acos(-1);
  cout << fixed <<  setprecision(10) << 2*pi*r << '\n';

}

Measured memory_bytes: 3808
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
    long long n,m,k,i,j,s=0,a=0,b=0,rz=0;
    cin>>n>>m;
    cout<<6-n-m;
    return 0;
}


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

int main(){
  int a,n,min = 1000000,max = -1000000;
  long sum = 0;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a;
    if(a < min)min = a;
    if(a > max)max = a;
    sum += a;
  }
  cout << min << ' ' << max <<  ' ' << sum <<  '\n';
  return 0;
}


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

using namespace std;

int main(){
    
    int M,N;
    
    scanf("%d%d",&M,&N);
    
	vector<tuple<int,int,int>> vec;
	
	for(int i=0;i<M;i++){
	    
		int l,r,x;
		
		scanf("%d%d%d",&l,&r,&x);
		
		vec.emplace_back(x,l-x,r-x);
		
	}
	
	vector<int> Time(N);
	
	set<int> st;
	
	for(int i=0;i<N;i++){
	    
		scanf("%d",&Time[i]);
		
		st.insert(Time[i]);
		
	}
	
	// Remember All the Time of the couple are distinct and are in increasing order......
	
	sort(vec.begin(),vec.end());
	
	map<int,int> ans;
	
	for(int i=0;i<M;i++){
	    
		int cor=get<0>(vec[i]), l=get<1>(vec[i]), r=get<2>(vec[i]);
		
		auto it1=st.lower_bound(l);
		
		auto it2=st.lower_bound(r);
		
		vector<int> done;
		
		while(it1!=it2){
		    
			ans[*it1]=cor;
			
			done.push_back(*it1);
			
			it1++;
			
		}
		
		for(int x : done) st.erase(x);
		
	}
	for(int i=0;i<N;i++){
	    
		if(ans.count(Time[i])) cout<<ans[Time[i]]<<endl;
		
		else cout<<"-1"<<endl;
		
	}
	
	return 0;
	
}    


Measured memory_bytes: 22128
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int x, t;
	cin >> x >> t;
	if (t >= x)cout << 0 << endl;
	else cout << x - t << endl;
}



Measured memory_bytes: 256
using System;
class ProgramB
    {
        static void Main(string[] args)
        {
            
            //入力
            string[] input = Console.ReadLine().Split(' ');
            long h = long.Parse(input[0]);
            long w = long.Parse(input[1]);

            if(h == 1 || w == 1)
                Console.WriteLine("1");
            else if(h % 2 == 1 && w % 2 == 1)
                Console.WriteLine(h*w /2 + 1);
            else
                Console.WriteLine(h*w /2);
    
        }
    }

Measured memory_bytes: 11092
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

#define fs first
#define sc second
#define MAX 1000000001
#define a(x) (x).begin(),(x).end()
#define pb push_back

int n,m;
int sum[5100][5100];
pair<int,int> p[5100];
vector<int> x,y;
int x1,y1,x2,y2;

int main(){
  scanf("%d%d",&n,&m);
  x.resize(n+2); y.resize(n+2);
  for(int i=0;i<n;i++){
    scanf("%d%d",&x[i],&y[i]);
    p[i].fs = x[i]; p[i].sc = y[i];
  }

  x[n] = MAX; x[n+1] = -MAX; 
  y[n] = MAX; y[n+1] = -MAX;
  sort(a(x)); sort(a(y));
  x.erase(unique(a(x)),x.end()); y.erase(unique(a(y)),y.end());

  for(int i=0;i<n;i++){
    p[i].fs = lower_bound(a(x),p[i].fs) - x.begin();
    p[i].sc = lower_bound(a(y),p[i].sc) - y.begin();
  }
  sort(p,p+n);

  int cnt = 0;
  for(int i=0;i<x.size();i++)
    for(int j=0;j<y.size();j++){
      if(!i || !j)sum[i][j] = 0;
      else sum[i][j] = sum[i][j-1] + sum[i-1][j] - sum[i-1][j-1];
      while(cnt<n && p[cnt].fs == i && p[cnt].sc == j){
	sum[i][j]++; cnt++;
      }
    }

  for(int i=0;i<m;i++){
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    x1 = lower_bound(a(x),x1)-x.begin()-1;
    y1 = lower_bound(a(y),y1)-y.begin()-1;
    x2 = upper_bound(a(x),x2)-x.begin()-1;
    y2 = upper_bound(a(y),y2)-y.begin()-1;
    printf("%d\n",sum[x2][y2] - sum[x2][y1] - sum[x1][y2] + sum[x1][y1]);
  }
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

double eps = 1e-12;

int main() {
    int x, y;
    cin >> x >> y;
    cout << (x+y+2) - __gcd(x, y) - 1 << endl;
}

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

using namespace std;
int main()
{ int x,a;
int sum=0;
cin>>x>>a;
for (int i=0;i<a;i++)
{  int s;
    cin>>s;
    sum+=s;
}
if (sum>=x)cout <<"Yes";
else cout <<"No";
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
cnt = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    cnt[a - 1] += 1
    cnt[b - 1] += 1

ans = "YES"
for i in range(n):
    if cnt[i] % 2 == 1:
        ans = "NO"
        break

print(ans)

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   

vector<vector<ll>> a(10001);
vector<ll>c(10001);
ll t=0;
vector<ll>m(10001);//訪問可否
vector<ll>r(10001);//各頂点の値
void dfs(ll k){
  //cout<<k<<endl;
  for(ll i=0;i<a[k].size();i++){
    if(m[a[k][i]]==0){
      r[a[k][i]]=c[t];
      t++;
      m[a[k][i]]=1;
      dfs(a[k][i]);
      
    }
  }
}

int main(){
  ll i,j,o;
  ll result=0,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n;cin>>n;
  
  ll x,y;
  for(i=0;i<n-1;i++){
    cin>>x>>y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  for(i=0;i<n;i++){cin>>c[i];result+=c[i];}
  sort(ALLR(c));
  dfs(1);
  cout<<result-c[0]<<endl;
  for(i=1;i<=n;i++){
    cout<<r[i]<<" ";
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 1408
#define taskname "test"

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
int n;
int dp[maxn];

void read_input()
{
    cin >> n;
}

void solve()
{
    fill(begin(dp), end(dp), 0);
    int cur = 0;
    dp[n] = n;
    dp[n - 1] = n * 1LL * n % mod;
    for(int i = n - 2; i > 0; --i)
    {
        if(i + 3 <= n)
            cur = (cur + dp[i + 3]) % mod;
        dp[i] = (dp[i + 1] + (n - 1) * 1LL * (n - 1) % mod + cur + i + 1) % mod;
    }
    cout << dp[1] << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}


Measured memory_bytes: 4224
/*package whatever //do not write package name here */

// Working program with FastReader 
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 

public class Main 
{ 
	static class FastReader 
	{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() 
		{ 
			br = new BufferedReader(new
					InputStreamReader(System.in)); 
		} 

		String next() 
		{ 
			while (st == null || !st.hasMoreElements()) 
			{ 
				try
				{ 
					st = new StringTokenizer(br.readLine()); 
				} 
				catch (IOException e) 
				{ 
					e.printStackTrace(); 
				} 
			} 
			return st.nextToken(); 
		} 

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

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

		double nextDouble() 
		{ 
			return Double.parseDouble(next()); 
		} 

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
	} 

	public static void main(String[] args) 
	{ 
		FastReader ob=new FastReader(); 
		char[] arr={'a','e','i','o','u'};
		
		
		String s = ob.next();
		for (int i=0;i<5 ;i++ ) {
		    if(s.charAt(0)==arr[i]){
		        System.out.println("vowel");
		        return;
		    }
		}
		System.out.println("consonant");
	
	
	} 
} 


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;cin >> n >> m;
	vector<int> cnt(n,1);
	vector<bool> red(n);
	red.at(0)=true;
	rep(i,m){
		int x,y;cin >> x >> y;
		x--;y--;
		cnt.at(x)--;
		cnt.at(y)++;
		if(red.at(x)) red.at(y)=true;
		if(cnt.at(x)==0) red.at(x)=false;
	}
	int ans=0;
	rep(i,n) if(red.at(i)) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 640
import numpy as np
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  ##list(chain.from_iterable(l)) ##flatten
from heapq import heappush, heappop

"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) ## 横一列
A = [int(input()) for _ in range(N)] ## 縦一列
lst = [list(map(int,input().split())) for i in range(M)] ## 二次元
"""

N = int(input())
A = list(map(int,input().split())) ## 横一列

lst = []
for i in range(N):
  lst.append([i+1, A[i]])

lst_sorted = sorted(lst, key=lambda x: x[1])

for i in range(N):
  print(lst_sorted[i][0])
    

Measured memory_bytes: 33960
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static PrintWriter pw = new PrintWriter(System.out);
    public static void main(String[] args) throws IOException {
        func();
        pw.flush();
        return;
    }

    static void func() throws IOException {
        int[] input = arrayOfInt();
        int n = input[0];
        int m = input[1];

        int MAX = Math.floorDiv(m, n);
        long ans = 1;
        int[] divisor = getDivisor(m);
        for(int i = divisor.length;0 < i;i--){
            if(divisor[i-1] <= MAX){
                ans = divisor[i-1];
                break;
            }
        }
        println(ans);
    }
    // 入力受け取り
    static String next() throws IOException {return br.readLine();}
    static int nextInt() throws IOException{return getInt(br.readLine());}
    static long nextLong() throws IOException{return getLong(br.readLine());}
    static String[] arrayOfString() throws IOException{return br.readLine().split(" ");}
    static int[] arrayOfInt() throws IOException{return toIntArray(arrayOfString());}
    // 変換
    static long getLong(String val) {return Long.parseLong(val);}
    static int getInt(String val) {return Integer.parseInt(val);}
    static int[] toIntArray(String[] array) {
        return Stream.of(array.clone()).mapToInt(Integer::parseInt).toArray();
    }
    static String joinToString(String[] array) {
        StringBuilder sb = new StringBuilder();
        for(int i = 0;i < array.length;i++) sb.append(array[i]);
        return sb.toString();
    }
    static int[] listToIntArray(List<Integer> list){
        int[] ret = new int[list.size()];
        for(int i = 0;i < ret.length;i++) {
            ret[i] = list.get(i);
        }
        return ret;
    }

    // 事前計算系
    static int[] getDivisor(int val){
        List<Integer> divisor = new ArrayList<>();
        for (int i = 1; i*i <= val; i++) {
            if (val % i != 0) continue;
            divisor.add(i);
            divisor.add(val/i);
        }
        int[] result = listToIntArray(divisor);
        Arrays.sort(result);
        return result;
    }
    static int[] getPrime(int from, int to){
        return IntStream.rangeClosed(from, to)
                .filter(i -> IntStream.rangeClosed(2, (int)Math.sqrt(i)).allMatch(j -> i%j !=0))
                .toArray();
    }


    // 出力
    static void println(Object val){pw.println(val);}
}

Measured memory_bytes: 28628
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let mut v: Vec<i32> = read_vec();
    let mut ans: i32 = 1;

    for i in 1..n {
        ans += 1;
      for j in 0..i {
        if v[j] > v[i] {
            ans -= 1;
            break;

        }
      }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


using namespace std;

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

    int A,B,C;
    cin>>A>>B>>C;
    int X;
    cin>>X;

    int count = 0;
    for (int i = 0; i <= A; i++)
    {
        for (int j = 0; j <= B; j++)
        {
            for (int k = 0; k <= C; k++)
            {
                if(i*500 + j*100 + k*50 == X)
                count++;
            }
            
        }
        
    }

    cout<<count;
    
    return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, K;
    cin >> N >> K;

    vector<ll> A(N);

    REP(i, N){
        cin >> A[i];
    }

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

    // 決め打ち二部探索の探索範囲
    long long left = -LINF, right = LINF;
    while (right - left > 1) {
        long long x = (left + right) / 2;
        // Sはx以下となる組み合わせの個数
        // Tは同じものを2回選んでx以下となる個数
        // 最後に(S-T)/2しているのは重複除外
        long long S = 0, T = 0;

        // A[i]を固定してA[i]*A[j]がx以下となる個数をカウントしていく
        for (int i = 0; i < N; ++i) {
            // A[i]が正のときは小さい方からカウント(単純に数えるとO(N)になるのでここも2分探索)
            if (A[i] > 0) {
                int l2 = -1, r2 = N;
                while (r2 - l2 > 1) {
                    int m = (l2 + r2) / 2;
                    if (A[i] * A[m] <= x) l2 = m;
                    else r2 = m;
                }
                S += r2;
            }
            // A[i]が負のときは大きい方からカウント
            else if (A[i] < 0) {
                int l2 = -1, r2 = N;
                while (r2 - l2 > 1) {
                    int m = (l2 + r2) / 2;
                    if (A[i] * A[m] <= x) r2 = m;
                    else l2 = m;
                }
                S += N - r2;
            }
            // A[i]=0のときA[i]*A[j]=0なのでxが0以上の時は必ず満たすのでN個分追加
            else if (x >= 0) S += N;
            // Tは同じものを２回選んだ時に条件を満たすものをカウント
            if (A[i] * A[i] <= x) ++T;
        }
        long long num = (S - T) / 2;
        if (num >= K) right = x;
        else left = x;
    }
    cout << right << endl;
    return 0;
}

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

int f(vector<int> a) {
  int c = 0;
  rep(i, a.size()) if(i + 1 != a[i]) ++c;
  return c;
}


int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, p.size()) {
    cin >> p[i];
  } 

  if(f(p) == 0 || f(p) == 2) {
    cout << "YES" << endl;
  } 
  else {
    cout << "NO" << endl;
  }

  return 0;
}


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

int r,co;
int mat[1000][1000];
string c[1000];

int main(){
  cin>>r>>co;
  for(int i=0;i<r;i++){
    cin>>c[i];  
  }
  if(c[0][0]=='#')mat[0][0]=1;
  for(int j=1;j<co;j++){
   if(c[0][j]=='#'&&c[0][j-1]=='.')mat[0][j]=1+mat[0][j-1];
   else mat[0][j]=mat[0][j-1];
  }
  for(int i=1;i<r;i++){
   if(c[i][0]=='#'&&c[i-1][0]=='.')mat[i][0]=1+mat[i-1][0];
   else mat[i][0]=mat[i-1][0];
   for(int j=1;j<co;j++){
     int a,b;
     if(c[i][j]=='#'&&c[i][j-1]=='.')a=1+mat[i][j-1];
   	 else a=mat[i][j-1];
     if(c[i][j]=='#'&&c[i-1][j]=='.')b=1+mat[i-1][j];
   	 else b=mat[i-1][j];
     mat[i][j]=min(a,b);
   }
  }
  cout<<mat[r-1][co-1];
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
	int W, H;

	while (1) {
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0)break;
		for (int i = 0; i < H; i++) {
			if (i % 2 == 0) {
				for (int j = 0; j < W; j++) {
					if (j % 2 == 0)	printf("#");
					else printf(".");
				}
				printf("\n");
			}
			else {
				for (int j = 0; j < W; j++) {
					if (j % 2 == 0)	printf(".");
					else printf("#");
				}
				printf("\n");
			}
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2604
#include <stdio.h>

int min(int a, int b)
{
    if (a > b)
        return b;
    else
        return a;
}

int main(void)
{
    int a, b, c, x, y;
    scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);
    long sum = 0;

    if (a + b > 2 * c)
        sum = min(x, y) * 2 * c;
    else
        sum = min(x, y) * (a + b);

    if (x > y) {
        sum += min(a, 2 * c) * (x - y);
    }
    else if (x < y) {
        sum += min(b, 2 * c) * (y - x);
    }

    printf("%ld", sum);
    return 0;
}

Measured memory_bytes: 128
def convert(a,b):
    if (int(a/b)):
        return convert(int(a/b), b)+str(a%b)
    return str(a%b)

def main():
    N=int(input())
    m=0
    ans=[]
    l=['z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y']
    while True:
        m=N%26
        ans.append(l[m])
        if m==0: N-=26
        else: N-=m
        N=N//26
        if N==0: break
    ans.reverse()
    print(''.join(ans))
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 9052
import math
A,B,H,M = map(int,input().split())
t1 = (30*H+M/2)*math.pi/180
x1 = A*math.cos(t1)
y1 = A*math.sin(t1)
t2 = M*math.pi/30
x2 = B*math.cos(t2)
y2 = B*math.sin(t2)
d = ((x1-x2)**2+(y1-y2)**2)**0.5
print(d)

Measured memory_bytes: 62456
#include<stdio.h>
#include<string.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define S(type,x) fscanf(stdin,"%"#type,&x)
//#define MAX(a,b) a>b?a:b
//#define MIN(a,b) a<b?a:b
const char code[10][10] = { "","',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ" };

int main() {
	int c = 0, a;
	char input[10001], *p;
	for (; ~fscanf(stdin, "%[^\n]*s", input) != NULL; puts("")) {
		getchar();
		p = input;
		c = 0;
		while (*p) {
			if (*(p + 1) != *p) {
				int i = *p - '0';
				a = strlen(code[i]);
				if (*p != '0') fprintf(stdout, "%c", code[i][c%a]);
				c = 0;
			}
			else c++;
			if (*p == '0'&&*(p + 1) == '0') putchar(' ');
			p++;
		}
	}
	return 0;
}

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

using namespace std;

std::string calc(const std::string& sd, const std::string& t) {
  if (sd.find('?') == std::string::npos) {
    if (sd.find(t) == std::string::npos) {
      return "";
    } else {
      return sd;
    }
  }

  int const sn = sd.size();
  int const tn = t.size();
  std::vector<int> tStartCandidates;
  for (int tStart = 0; tStart < sn - tn + 1; tStart++) {
    bool found = true;
    for (int ti = 0; ti < tn; ti++) {
      char const sdCh = sd[tStart + ti];
      if (sdCh != '?' && sdCh != t[ti]) {
        found = false;
        break;
      }
    }
    if (!found) {
      continue;
    }
    tStartCandidates.push_back(tStart);
  }
  std::string ret = "";
  for (auto const tStart : tStartCandidates) {
    std::string candidate = sd;
    std::replace(candidate.begin(), candidate.end(), '?', 'a');
    candidate.replace(tStart, tn, t);
    if (ret.empty() || candidate < ret) {
      ret = candidate;
    }
  }
  return ret;
}

int main() {
  std::string sd;
  std::string t;
  std::cin >> sd;
  std::cin >> t;
  std::string ret = calc(sd, t);
  if (ret.size() == 0) {
    ret = "UNRESTORABLE";
  }
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
 
int main(){
	int N,M,X; cin>>N>>M>>X;
	int l = 0, r = 0;
	rp(i, 0, M){
		int a; cin>>a;
		if(a < X) l++;
		else r++;
	}
	cout<< min(l, r) <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << 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; }

long long N,cnt[5];
char check[5]={'M','A','R','C','H'};

int main(){
    cin>>N;
    string S[N];
    rep(i,N){
        cin>>S[i];
        rep(j,5){
            if(S[i][0]==check[j]){
                // out("yss");
                cnt[j]++;
            }
        }
    }
    long long ans=0;
    rep(i,5){
        repi(j,i+1,5){
            repi(k,j+1,5){
                ans+=cnt[i]*cnt[j]*cnt[k];
                // printf("%d %d %d\n",i,j,k);
            }
        }
    }
    out(ans);
}


Measured memory_bytes: 6144
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
#define time_passed 1.0 * clock() / CLOCKS_PER_SEC
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;

int main()
{
    fio;
    ll t, c, p, a, n, q, k, i, l, m, u, f, j, x, y, b, d;
    cin >> n;
   
for(i=1;;i++)
if( (i*(i+1))/2 > n ){break;}
else if ((i * (i + 1)) / 2 == n)break;
    cout << i ;
return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <stdio.h>
#include <string>

#define PI 3.141592653589793238

using namespace std;

int main(){
	while(true){
		int a,b;
		int ans = 0;
		char op /*= (char*)malloc(255*sizeof(char))*/;
		//string op;
		cin >> a >> op >> b;
		
		if(op == '?') break;
		
		switch(op){
		case '+':
			ans = a + b;
			break;
		case '-':
			ans = a - b;
			break;
		case '/':
			ans = a / b;
			break;
		case '*':
			ans = a * b;
			break;
		}
		
		cout << ans << endl;
	
	}
}


Measured memory_bytes: 3088
# coding: utf-8
import sys
import itertools


def sr(): return sys.stdin.readline().rstrip()


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


def check(sws):
    on_list = []
    for i in range(M):
        on = 0
        for s in d_dict[i + 1]:
            on += sws[s]
        if on % 2 == p_list[i]:
            on_list.append(True)
        else:
            on_list.append(False)

    return all(on_list)


ans = 0


def dfs(depth, sws):
    global ans

    if depth == 0:
        return check(sws) * 1

    for i in range(2):
        t_sws = sws
        t_sws[depth] = i
        on = dfs(depth - 1, t_sws)
        ans += on

    return 0


N, M = lr()
d_dict = {}
for i in range(M):
    s_list = lr()
    d_dict[i + 1] = s_list[1:]

p_list = lr()

sw_list = [0] * (N + 1)
dfs(N, sw_list)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const MAXN=2.2e6;
int const MD=998244353;

int madd(int x,int y) {
	if (x+y<MD) return x+y; else return x+y-MD;
}
int msub(int x,int y) {
	if (x-y>=0) return x-y; else return x-y+MD;
}
int mmul(int x,int y) {
	return int(ll(x)*y % MD);
}
int mpow(int x,int p) {
	int res=1;
	while (p>0) {
		if (p%2) res=mmul(res,x);
		x=mmul(x,x);
		p/=2;
	}
	return res;
}
int minv(int x) {
	return mpow(x,MD-2);
}
int mdiv(int x,int y) {
	return mmul(x,mpow(y,MD-2));
}

template<int N>
struct mod_comb {
	vector<int> f,rf;
	mod_comb():f(N),rf(N) {
		f[0]=rf[0]=1;
		rep(i,1,N) {
			f[i]=mmul(f[i-1],i);
			rf[i]=minv(f[i]);
		}
	}
	int comb(int n,int k) {
		if (n<k) return 0;
		return mmul(f[n],mmul(rf[n-k],rf[k]));
	}
	int distr(int n,int k) {
		return comb(n+k-1,k-1);
	}
};

mod_comb<MAXN> mcomb;
#define comb(n,k) mcomb.comb(n,k)
#define distr(n,k) mcomb.distr(n,k)

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

	int N,M;
	cin>>N>>M;
	
	int res=0;
	rep(i,0,min(N,M)+1) if ((3*M-i)%2==0) {
		int add=mmul(comb(N,i),distr((3*M-i)/2,N));
		res=madd(res,add);
	}
	rep(i,0,min(N,M)+1) if ((M-i)%2==0) {
		int sub=mmul(comb(N,i),distr((M-i)/2,N));
		res=msub(res,mmul(sub,N));
	}
	rep(i,0,min(N,M)+1) if ((M-i)%2==0) {
		int add=mmul(comb(N-1,i),distr((M-i)/2,N-1));
		res=madd(res,mmul(add,N));
	}
	cout<<res<<'\n';
}


Measured memory_bytes: 17408
N = int(input())
S = input()
ans = 0
for i in range(10**3):
    s = str(i).zfill(3)
    flag = 0
    for j in range(N):
        if s[flag]==S[j]:
            flag += 1
            if flag == 3:
                break
    if flag==3:
        ans += 1
print(ans)

Measured memory_bytes: 41052
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <stdlib.h>
#include <numeric>


int main(){
	int sum[100001] = {}, n, m, input;
	bool broken[100001] = {};
	std::cin >> n >> m;
	for(int i = 0; i < m; i++){
		std::cin >> input;
		broken[input] = true;
	}
	for(int i = 0; i < n + 1; i++){
		if(i == 0){
			sum[i] = 1;
		}else if(i == 1 && !broken[i]){
			sum[i] = sum[0];
		}else if(!broken[i]){
			sum[i] = sum[i - 1] + sum[i - 2];
			sum[i] %= 1000000007;
		}
	}
	std::cout << sum[n] << std::endl;
	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
struct Node{
	int l,r;
}a[100010];
bool cmp(Node a,Node b){
	if(a.r==b.r)return a.l<b.l;
	return a.r<b.r;
}
int main(){
	int n;
	scanf("%d",&n);
	int r=0,s=1;
	for(int i=0,x,l;i<n;i++){scanf("%d%d",&x,&l);a[i].l=x-l,a[i].r=x+l;}
	sort(a,a+n,cmp);
	r=a[0].r;
	for(int i=0;i<n;i++){
		if(a[i].l>=r)r=a[i].r,s++;
	}
	printf("%d",s);
}

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

const char *str[] = {
    "light fly","fly","bantam","feather","light","light welter",
    "welter","light middle","middle","light heavy","heavy"
};
const double n[] = { 48,51,54,57,60,64,69,75,81,91,1e9 };

#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)
#define ESIZEOF(A)      (sizeof(A)/sizeof((A)[0]))

int main(){
    double d;
    while(cin >> d){
        REP(i,ESIZEOF(n)){
            if(d <= n[i]){
                cout << str[i] << endl;
                break;
            }
        }
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
const ll INF = 1000000000000000000LL;

// A function to print all prime
// factors of a given number n
map<ll, ll> primeFactors(ll n) {
    map<ll, ll> ans;
    // Print the number of 2s that divide n
    while (n % 2 == 0) {
        ++ans[2];
        n = n / 2;
    }

    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll i = 3; i <= sqrt(n); i = i + 2) {
        // While i divides n, print i and divide n
        while (n % i == 0) {
            ++ans[i];
            n = n / i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        ++ans[n];
    return ans;
}

ld f(ll x) { return (-1.0 + sqrtl(1.0 + 8.0 * x)) / 2.0; }

int main() {
    ll N;
    cin >> N;
    auto factors = primeFactors(N);
    ll ans = 0;
    for (const auto &p : factors) {
        ll x = p.second;
        ans += static_cast<ll>(floorl(f(x)));
    }
    cout << ans << endl;
    return 0;
}

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


int main() {
  int N, M; cin >> N >> M;
  vector<int> p(M);
  vector<string> s(M);
  rep(i, M) {
    cin >> p[i];
    cin >> s[i];
  }
  
  int ac = 0, wa = 0;
  vector<int> pr(N, 0);
  
  rep(i, M) {
    if(pr[p[i]-1] >= 0) {
      if(s[i] == "WA") pr[p[i]-1]++;
      else {
        wa += pr[p[i]-1];
        pr[p[i]-1] = -1;
        ac++;
      }
    }
  }
        
  
  cout << ac << " " << wa << endl;

}


Measured memory_bytes: 6528
n,y = map(int, input().split())
flg = False
for a in range(n+1):
  for b in range(n+1):
    c = n-(a+b)
    if y == a*10000 + b*5000 + c*1000 and a+b <=n:
      print(a,b,c)
      flg =True
      break
  if flg:
    break
else:
  print(-1,-1,-1)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define repl(k,n) for(k=0;k<n;++k)

int main() {
	string S;
	cin >> S;
	int count=0;
	if (S[1] == 'R') {
		if (S[0] != 'R'&&S[2]!='R') {
			count = 1;
		}
		else if (S[0] != 'R' || S[2] != 'R') {
			count = 2;
		}
		else {
			count = 3;
		}
	}
	else {
		if (S[0] == 'R' || S[2] == 'R')count = 1;
		else count = 0;
	}
	cout << count;
	return 0;
}

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

//atcoder need change class name to Main
//G - Longest Path
//refer to https://www.geeksforgeeks.org/longest-path-in-a-directed-acyclic-graph-dynamic-programming/
//https://atcoder.jp/contests/dp/tasks/dp_g

//An efficient approach is to use Dynamic Programming and DFS together to find the longest path in the Graph.

public class Main {
    static StringTokenizer st;
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    static ArrayList<Integer> edge[];
    public static void main(String[] args) throws IOException {
  
        int N = nextInt(); 
        int M = nextInt(); 
 
        edge = new ArrayList[N+1];
        for (int i=1; i<=N;  i++) {
            edge[i] = new ArrayList<>();
        }

        for (int i=0; i<M;  i++) {
            int x = nextInt(); 
            int y = nextInt(); 
            edge[x].add(y);
        }

    
        // Dp array 
        int[] dp = new int[N+1]; 
  
        // Visited array to know if the node 
        // has been visited previously or not 
        boolean[] visited = new boolean[N + 1]; 
  
        // Call DFS for every unvisited vertex 
        for (int i = 1; i <= N; i++)  
        { 
            if (!visited[i]) 
                dfs(i, dp, visited); 
        } 
  
        int ans = 0; 
  
        // Traverse and find the maximum of all dp[i] 
        for (int i = 1; i <= N; i++)  
        { 
            ans = Math.max(ans, dp[i]); 
        }  
        
        System.out.println(ans);
  
    }
    
    static void dfs(int node
            , int dp[]
            , boolean visited[]) 
    { 
        // Mark as visited 
        visited[node] = true; 

        // Traverse for all its children 
        for (int i = 0; i < edge[node].size(); i++)  
        { 
            int ChildNode = edge[node].get(i);
            // If not visited 
            if (!visited[ChildNode]) 
                dfs(ChildNode, dp, visited); 

            // Store the max of the paths 
            dp[node] = Math.max(dp[node], 1 + dp[ChildNode]); 
        } 
    } 

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }
}

Measured memory_bytes: 61920
import sys
input = sys.stdin.readline
A, B = map(int, input().split())

def gcd(a, b):
    if b==0:
        return a
    else:
        return gcd(b, a%b)

def fac(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

gcdv = gcd(A, B)
l = fac(gcdv)
ans = len(l)

if ans == 1:
    if l[0][0] == 1:
        print(1)
    else:
        print(ans+1)
else:
    print(ans+1)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int a, b, c, d, k, found=0;
    scanf("%d %d", &a, &b);
    for(k=0; k<1000000000; k++)
    {

        c=a-k;
        if(c<0)
            c=c*(-1);
        d=b-k;
        if(d<0)
            d=d*(-1);

        if(c==d)
        {
            found=1;
            break;
        }

    }
    if(found)
        printf("%d\n", k);
    else
        printf("IMPOSSIBLE\n");
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

tuple<vector<int>, vector<vector<int>>> input(const int D)
{
  vector<int> c(26);
  for (int i = 0; i < 26; ++i)
    cin >> c[i];
  vector<vector<int>> s(D, vector<int>(26));
  for (int i = 0; i < D; ++i)
  {
    for (int j = 0; j < 26; ++j)
      cin >> s[i][j];
  }
  return forward_as_tuple(c, s);
}

vector<int> calculate(const int D, const vector<int> &c, const vector<vector<int>> &s, const vector<int> &t)
{
  int sum = 0;
  vector<int> last(26, 0);
  vector<int> ret;
  for (int i = 0; i < D; ++i)
  {
    sum += s[i][t[i]];
    last[t[i]] = i + 1;
    for (int j = 0; j < 26; ++j)
    {
      sum -= c[j] * (i + 1 - last[j]);
    }
    ret.push_back(sum);
  }

  return ret;
}

int main()
{
  int D;
  cin >> D;
  auto tmp = input(D);
  auto c = get<0>(tmp);
  auto s = get<1>(tmp);

  vector<int> t(D);
  for (int i = 0; i < D; ++i)
  {
    cin >> t[i];
    t[i]--;
  }

  auto val = calculate(D, c, s, t);
  for (int i = 0; i < D; ++i)
    cout << val[i] << endl;

  return 0;
}

Measured memory_bytes: 3544
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
int m, n, d[559], e[559]; bool canvis[559], vis[559];
int main() {
	while (cin >> m, m) {
		cin >> n;
		fill(d, d + 555, 0);
		for (int i = 1; i <= n; i++) cin >> d[i];
		for (int i = 0; i < 555; i++) {
			int p = i + d[i];
			p = min(p, n + 1);
			p = max(p, 0);
			e[i] = p;
		}
		queue<int> que1; que1.push(0);
		fill(canvis, canvis + 555, false); canvis[0] = true;
		while (!que1.empty()) {
			int u = que1.front(); que1.pop();
			for (int i = 1; i <= m; i++) {
				int t = e[u + i];
				if (!canvis[t]) {
					canvis[t] = true;
					que1.push(t);
				}
			}
		}
		bool ret = true;
		for (int i = 0; i <= n + 1; i++) {
			if (!canvis[i]) continue;
			fill(vis, vis + 555, false); vis[i] = true;
			queue<int> que2; que2.push(i);
			while (!que2.empty()) {
				int u = que2.front(); que2.pop();
				for (int j = 1; j <= m; j++) {
					int t = e[u + j];
					if (!vis[t]) {
						vis[t] = true;
						que2.push(t);
					}
				}
			}
			if (!vis[n + 1]) ret = false;
		}
		cout << (ret ? "OK" : "NG") << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
const int maxn = 1e5+10;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
int d[4][2]={1,0,0,1,-1,0,0,-1};
ll poww(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1) ans*=x;
        x*=x;
        y>>=1;
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(0);
    #ifdef Uncle_drew
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    #else
    #endif
    map<ll,pair<int,int>> ma;
    for(ll i=-500;i<=500;i++){
        for(ll j=-500;j<=500;j++){
            ll mid=poww(i,5)-poww(j,5);
            ma[mid]=mp(i,j);
        }
    }
    ll x;
    cin>>x;
    cout<<ma[x].first<<" "<<ma[x].second<<endl;
    return 0;
}

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

using namespace std;

int main(){
	int n, q, i, j, key, cnt = 0;
	int sin, tin;
	vector<int> S, T;
	
	cin >> n;
	for(i=0;i<n;++i){
		cin >> sin;
		S.push_back(sin);
	}
	cin >> q;
	for(i=0;i<q;++i){
		cin >> tin;
		T.push_back(tin);
	}
	
	for(i=0;i<q;++i){
		key = T[i];
		for(j=0;j<n;++j){
			if(S[j] == key){
				cnt++;
				break;
			}
		}
	}
	cout << cnt << endl;
	
	return 0;
}


Measured memory_bytes: 3228