akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { //Perform BFS from 2...N then use those values to print

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		ArrayList<Integer>[] graph = new ArrayList[N+1];
		for (int i = 1; i<=N; i++) {
			graph[i]=new ArrayList<Integer>();
		}
		for (int i = 0; i < M; i++) {
			int A = input.nextInt();
			int B = input.nextInt();
			graph[A].add(B);
			graph[B].add(A);
		}
		int[] ans = BFS(graph);
		boolean bad = false;
		for (int i = 2; i <= N; i++) {
			if (ans[i]==0) {
				bad=true;
				break;
			}
		}
		if (bad) System.out.println("No");
		else {
			System.out.println("Yes");
			for (int i = 2; i <= N; i++) {
				System.out.println(ans[i]);
			}
		}
	}	
	public static int[] BFS(ArrayList<Integer>[] graph) {
		int[] ans = new int[graph.length];
		boolean[] vis = new boolean[graph.length];
		Queue<Integer> cur = new LinkedList<Integer>();
		cur.add(1);
		while (!cur.isEmpty()) {
			int size = cur.size();
			for (int i = 0; i < size; i++) {
				int curSTART = cur.poll();
				for (int j = 0; j < graph[curSTART].size(); j++) {
					if (!vis[graph[curSTART].get(j)]) {
						ans[graph[curSTART].get(j)]=curSTART;
						vis[graph[curSTART].get(j)]=true;
						cur.add(graph[curSTART].get(j));
					}
				}
			}
		}
		return ans;
	}
}

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

using namespace std;

int main(){

  string S;
  cin >>S;
  if(S[0]==S[1])
    cout<<"Bad"<<endl;
  else if(S[1]==S[2])
    cout<<"Bad"<<endl;
  else if(S[2]==S[3])
    cout<<"Bad"<<endl;
  else
    cout<<"Good"<<endl;

  return 0;
}


Measured memory_bytes: 256
/*
____    ____ .___________.
\   \  /   / |           |
 \   \/   /  `---|  |----`
  \      /       |  |     
   \    /        |  |     
    \__/         |__|     
                          
 */


#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<iomanip>
#define ll long long
#define mod 1000000007
using namespace std;
const int INF = 2e9 + 1;


/*---------------Graph Class---------*/
class graph
{
private:
	ll novert;
	ll noedges;
	vector< vector<ll> > adjlist;
public:
	graph(ll n,ll m)
	{
		novert=n;
		noedges=m;
		adjlist.resize(n+1);	
	}
	
	void addedge(ll u,ll v)
	{
		//bidirectional
		adjlist[u].push_back(v);
		adjlist[v].push_back(u);	
	}
	
	void dfsutil(ll initvert,vector<bool>& visited,ll lastvert=-1)
	{
		if(lastvert==initvert)
		{
			//do something
		}
		visited[initvert]=true;
		for(auto itr:adjlist[initvert])
		{
			if(!visited[itr])
			{
			}	
		}	
	}	
};
/*-----------------End of graph----------------*/





int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

string s;
cin>>s;
vector<char> ans;

for(auto itr:s)
{
	if(ans.empty()&&itr=='B')
	{
		continue;
	}
	if(itr=='B')
	{
		ans.erase(ans.end()-1);
	}
	else
	ans.push_back(itr);
}

for(auto itr:ans)
{
	cout<<itr;
} 

	return 0;
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define mod 1000000007
#define b1(n) __builtin_popcount(n)
vector<int>sie; 
 inline int gEd(int a, int b, int *ax, int *ay) 
{ 
	int x,y;  
	if (a==0) 
	{   *ax=0;
		*ay = 1; 
		return b;
	}
    int g = gEd(b%a,a,&x,&y);
    *ax=y-(b/a)*x; 
	*ay=x; 
	return g; 
}  
inline int mli(int a,int m) //mli(a,m)
{
	int ax,ay;
	     gEd(a,m,&ax,&ay);
	    int val1=(ax%m+m)%m; 
	    return val1;
}
inline int powerm(int a,int n)   //powerm(a,n)
{
	int ans=1;
	while(n>0)
	{
		int last_bit=(n&1);
		if(last_bit)
		ans=((ans%mod)*(a%mod))%mod;
		a=((a%mod)*(a%mod))%mod;
		n=n>>1;
	}
	return ans;
}
inline int power(int a,int n)   //power(a,n)
{
	int ans=1;
	while(n>0)
	{
		int last_bit=(n&1);
		if(last_bit)
		ans=ans*a;
		a=a*a;
		n=n>>1;
	}
	return ans;
}
inline int add(int a,int b)
{
	int s=((a%mod)+(b%mod))%mod;
	return s;
}
inline int sub(int a,int b)
{
	int s=((a%mod)-(b%mod))%mod;
	return s;
}
inline int mul(int a,int b)
{
	int s=((a%mod)*(b%mod))%mod;
	return s;
}
inline int ncr(int n, int k)  //ncr(a,b)
{ 
    int res = 1; 
  
 
    if (k > n - k) 
        k = n - k; 
  
  
    for (int i = 0; i < k; ++i) { 
        res *= (n - i); 
        res /= (i + 1); 
    } 
  
    return res; 
} 
inline void sieve()   //sieve vector->sie
{
	const int n=10000000;
	bitset<10000000>b;
	b.set();
	b[0]=b[1]=0;
	for(int i =2;i<=n;i++)
	{
		if(b[i])
		{
			sie.push_back(i);
			for(int j=i*i;j<=n;j=j+i)
			b[j]=0;
		}
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     string s;
     int n;
     cin>>n >>s;
     string s1;
     for(int i=0;i<s.length();i++)
     {
		 int k=(int)s[i];
		 k=k+n;
		 if(k>90)
		 {
			 k=(k-90)+64;
		 }
		 s1=s1+(char)k;
	 }
	 cout << s1 ;
	 
   
    
		
		
		
    
    
}


Measured memory_bytes: 3792
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
//#define MOD 1000000007

using namespace std;
const long long MOD=998244353;

ll dp[90005];
ll dp2[90005];

ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    vector<long> a(n);
    long i;
    long sum=0;
    for(i=0; i<n; i++) {
        scanf("%ld", &a[i]);
        sum += a[i];
    }
    long sum2=(sum+1)/2;

    long j;
    dp[0]=1;
    dp2[0]=1;
    for(i=1; i<=n; i++) {
        for(j=sum; j>=0; j--) {
            dp2[j] = dp2[j]*2%MOD;
            if(j>=a[i-1]) {
                dp[j]=(dp[j]+dp[j-a[i-1]])%MOD;
                dp2[j]=(dp2[j]+dp2[j-a[i-1]])%MOD;
            }
        }
    }

    ll val0=0;
    for(i=sum2; i<sum-1; i++) {
        val0 = (val0 + (dp2[i]-2*dp[i]+2*MOD))%MOD;
    }

    ll ans = (mpow(3,n) - (mpow(2,n)*3) +3 +3*MOD)%MOD;
    ans = (ans -val0*3 +MOD*3)%MOD;
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 1664
def gcd_all(a):
    from math import gcd
    g = 0
    for x in a: g = gcd(g, x)
    return g

def is_pairwise():
    MAX_A = 10**6 + 1
    C = [0] * MAX_A
    for a in A: C[a] += 1
    if sum(C[2::2]) > 1: return False
    for i in range(3, MAX_A, 2):
        if sum(C[i::i]) > 1: return False
    return True

def solve():
    if is_pairwise(): return 0
    if gcd_all(A) == 1: return 1
    return 2

n = int(input())
A = [*map(int, input().split())]
print(['pairwise','setwise','not'][solve()], 'coprime')


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

int main(){
  int x;
  cin >> x;
  
  int max=1;
  rep(i,x+1){
    rep(b,x/2+1){
      for(int p=2;p<10;p++){
        if(i==pow(b,p) && i > max){
          max = i;
        }
      }
    }
  }
  
  cout << max << endl;
  
  return 0;
}


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

int n;
int cnt[2] = {};
vector<vector<int>> edge, lst;
vector<int> res, memo;

void solve();
void dfs(int now, int dis);
void pattern3(bool ch);
void pattern12();

int main() {
  cin >> n;
  edge.resize(n);
  for(int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  solve();
  for(int i = 0; i < n; ++i) cout << res[i] << " ";
  cout << endl;
  return 0;
}

void solve() {
  res.resize(n);
  memo.assign(n, -1);
  dfs(0, 0);
  if(cnt[0] <= n / 3)
    pattern3(0);
  else if(cnt[1] <= n / 3)
    pattern3(1);
  else
    pattern12();
}

void pattern3(bool ch) {
  int nc[3] = {};
  for(int i = 0; i < n; ++i) {
    if(memo[i] % 2 == ch)
      res[i] = ++nc[2] * 3;
    else {
      res[i] = ++nc[0] * 3 - 2;
      if(res[i] > n) res[i] = ++nc[1] * 3 - 1;
      if(res[i] > n) res[i] = ++nc[2] * 3;
    }
  }
}

void pattern12() {
  int nc[3] = {};
  for(int i = 0; i < n; ++i) {
    res[i] = ++nc[memo[i] % 2] * 3 - 1 - memo[i] % 2;
    if(res[i] > n) res[i] = ++nc[2] * 3;
  }
}

void dfs(int now, int dis) {
  ++cnt[dis % 2];
  memo[now] = dis;
  for(auto p : edge[now])
    if(memo[p] == -1) dfs(p, dis + 1);
}


Measured memory_bytes: 15488
"use strict";

const main = arg => {
    const inputList = arg.trim().split("\n");
  // 回答を記述
  const N = parseInt(inputList[0].split(' ')[0]);
  // [高さ, 隣より高いbool]
  const peaks = inputList[1].split(' ').map(ele => parseInt(ele)).map(ele => [ele, true]);
  // 道のリスト（idx >= 2）から隣以下の高さであればboolをfalseにする
  for (let i = 2; i < inputList.length; i++) {
    // idxにするために -1
    const AB = inputList[i].split(' ').map(ele => parseInt(ele) - 1);
    if (peaks[AB[0]][0] <= peaks[AB[1]][0] ) peaks[AB[0]][1] = false;
    if (peaks[AB[0]][0] >= peaks[AB[1]][0] ) peaks[AB[1]][1] = false;
  }
  // 高いbool == true　の要素数を出力する
  console.log(peaks.filter(ele => ele[1] == true).length)

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 79036
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V  = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class H> void rsz(V<T> &v, H h) { v.resize(h); }
template<class T, class H, class... R> void rsz(V<T> &v, H h, R... r) { v.resize(h); for (auto&& i : v) rsz(i, r...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  string s; cin >> s;
  V<> n(3); for (char c : s) n[c - 'a']++;
  sort(n.begin(), n.end());
  cout << (n[2] - n[0] <= 1 ? "YES" : "NO") << '\n';
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------



void solve() {
	int i,j,k,l,r,x,y; string s;
	int A[3];
	cin>>A[0]>>A[1]>>A[2];
	cout<<A[0]*A[1]/2<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   long int n;
   cin>>n;


   string s;
   cin>>s;

   bool w = false;
   long int ans1 = 0;
   long int ans2 = 0;

   for(auto ele : s){
    if(ele == 'W')
      w = true;
    else
      ans1 += w;
   }

   bool r = false;

   for(long int i = n - 1; i >= 0; i--){
    if(s[i] == 'R')
      r = true;
    else
      ans2 += r;
   }

   long int redCount = 0, whiteCount = 0;

   for(auto ele : s){
    if(ele == 'R')
      redCount++;
    else
      whiteCount++;
   }

   long int ans3 = 0;
   for(long int i = 0; i < redCount; i++)
    if(s[i] == 'W')
      ans3++;

   long int ans4 = 0;
   for(long int i = 0; i < whiteCount; i++)
    if(s[n - i - 1] == 'R')
      ans4++;

   cout<<min({ans1,ans2,ans3,ans4});
   return 0;
}

Measured memory_bytes: 3764
#include <iostream>

int main() {    
    int array[3];   
    for (int i=0; i<3; i++) {
        std::cin >> array[i];
    }
        
    int countFor5 = 0;
    int countFor7 = 0;
    for (int i=0; i<3; i++) {
        if (array[i] == 5) {
            countFor5++;
        } else if (array[i] == 7) {
            countFor7++;
        }
    } 
        
    if (countFor5==2 && countFor7==1) {         
        std::cout << "YES" << std::endl;                
    } else {
        std::cout << "NO" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc148/submissions/9089396

N, M = map(int, input().split())
graph = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

memo = {}
all_use = (1 << N) - 1

def rec(v, use):
    if use == all_use:
        return 1

    key = (v, use)
    if key in memo:
        return memo[key]

    res = 0
    for u in graph[v]:
        if (use >> u) & 1 == 1:
            continue

        use ^= 1 << u
        res += rec(u, use)
        use ^= 1 << u

    memo[key] = res
    return res

print(rec(0, 1))


Measured memory_bytes: 3064
#include <iostream>
 
using namespace std;
 
int main(void)
{
    int A, B, sum=0, i;
 
    cin >> A >> B;
 
    for(i=1; i<=2; i++){
	if(A>B){
	    sum += A;
	    A--;
	}
	else{
	    sum += B;
	    B--;
	}
    }
 
    cout << sum << endl;
 
    return 0;
}

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

using namespace std;

// Count the number of 1s in a bit sequence 
int count(int b) {
  int res = 0;
  while (b != 0) {
    b = b & (b - 1);
    ++res;
  }
  return res;
}

int main() {
  int N, K; cin >> N >> K;
  int a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  long long ans = INT64_MAX;
  for (int i = 0; i < (1 << N); i++) {
    if (count(i) != K) continue; 

    long long cost = 0;
    int requirement = 0; 
    for (int j = 0; j < N; j++) {
      // Be especially careful with & and == in same statement 
      if (((i >> j) & 1) == 0) {
        requirement = max(requirement, a[j] + 1);
        continue;
      } 
      if (requirement > a[j]) {
        cost += requirement - a[j];
        requirement++;
      } else {
        requirement = a[j] + 1;
      }
    }

    ans = min(ans, cost);
  }

  cout << ans << endl;
}

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

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

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  int a;
  REP(i, n) {
    cin >> a;
    mp[a]++;
  }

  
  vector<ULL> edges;

  for(auto iter = mp.rbegin(); iter != mp.rend(); ++iter) {
    int k = iter->first;
    int v = iter->second;
    eprintf("k,v:%d,%d\n", k,v);
    if(v >= 4) {
      edges.push_back(k);
      edges.push_back(k);
      break;
    }
    else if(v >= 2) {
      edges.push_back(k);
      if(edges.size() >= 2) {
        break;
      }
    }
  }

  if(edges.size() >= 2) {
    ULL ans = edges[0] * edges[1];
    cout << ans << endl;
  }
  else {
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 4992
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

	public void Proc()
	{
        int pointCount = int.Parse(Reader.ReadLine());
        Dictionary<int, Dictionary<int, int>> path = new Dictionary<int, Dictionary<int, int>>();
        for (int i = 0; i < pointCount; i++) {
            int[] inpt = Reader.ReadLine().Split(' ').Skip(2).Select(a => int.Parse(a)).ToArray();
            for (int j = 0; j < inpt.Length; j+=2) {
                if(!path.ContainsKey(i)) {
                    path.Add(i, new Dictionary<int, int>());
                }
                path[i][inpt[j]] = inpt[j + 1];
            }
        }
        Queue<int> que = new Queue<int>();
        Nullable<int>[] steps = new Nullable<int>[pointCount];
        steps[0] = 0;
        que.Enqueue(0);
        while(que.Count() > 0) {
            int current = que.Dequeue();
            if(!path.ContainsKey(current)) {
                continue;
            }
            path[current].Keys.ToList().ForEach(a =>
            {
                int nextStep = steps[current].Value + path[current][a];
                if (steps[a] == null || steps[a] > nextStep)
                {
                    steps[a] = nextStep;
                    que.Enqueue(a);
                }
            });
        }

        System.Text.StringBuilder ans = new System.Text.StringBuilder();
        for (int i = 0; i < pointCount; i++) {
            ans.AppendLine(i + " " + steps[i]);
        }
        Console.Write(ans.ToString());
    }


	public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"


10
0 2 1 1 2 3
1 2 3 3 2 1
2 2 3 1 6 10
3 1 4 1
4 1 7 1
5 2 3 1 6 1
6 2 3 1 8 1
7 2 5 1 8 4
8 1 9 100000
9 0

";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}

Measured memory_bytes: 11564
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<queue>
#define pr(x) cout<<#x<<" "<<x;
#define pl(x) cout<<#x<<" "<<x<<endl;
#include<math.h>
#include<algorithm>
using namespace std;
int dx[] = {-1,1,0,0};
int dy[] = {0,0,-1,1};
char maze[105][105];
int h,w;
void dfs(int x,int y,char c){
    maze[x][y] = '.';
    for(int i=0;i<4;i++){
        int nx = x+dx[i];
        int ny = y+dy[i];
        if(nx>=0&&nx<h&&ny>=0&&ny<w&&maze[nx][ny]==c){
            dfs(nx,ny,c);
        }
    }

}
int main(){


    while(cin>>h>>w,w>0){
        int ans = 0;
        getchar();
        for(int i = 0;i< h;i++){
            scanf("%s",&maze[i]);

        }
        for(int i = 0;i<h;i++){
            for(int j = 0;j<w;j++){
                if(maze[i][j]=='#')
                {
                  dfs(i,j,'#');
                  ans++;
                  continue;
                }
                if(maze[i][j]=='@')
                {
                  dfs(i,j,'@');
                  ans++;
                  continue;
                }
                if(maze[i][j]=='*')
                {
                  dfs(i,j,'*');
                  ans++;
                  continue;
                }
            }
        }
        cout<<ans<<endl;
    }

}

Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<cstring>
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> ii;

ll t;

char str[10];

int main()
{
//     cin>>t;
//     while(t--){
//
//     }
    ll x,res;
    cin>>x;
    res=1000*(x/500);
    x%=500;
    res+=5*(x/5);
    cout<<res<<endl;
}


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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef long long ll;
typedef pair<int, int> pi;

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

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

    int maxi = 0;
    int prev = 0;
    for (int i=n-2;i>=0;i--){
        if (A[i]>=A[i+1]) prev++;
        else prev = 0;
        maxi = max(maxi , prev);
    }   
    cout<<maxi<<endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
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;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,w,a[110],b[110],dp[110][100010];
signed main(){
    cin>>n>>w;
    rep(i,n)cin>>a[i]>>b[i];
    rep(i,n+1){
        rep(j,100010){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=100000;j++){//value
            chmin(dp[i+1][j],dp[i][j]);
            chmin(dp[i+1][j+b[i]],dp[i][j]+a[i]);
        }
    }
    int ans=0;
    rep(i,100001)if(dp[n][i]<=w)ans=i;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 82304
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
typedef long long ll;
const int N=200000;
ll fac[N+5],inv[N+5];
int h,w,a,b;
ll fast_pow(int a,int b)
{
	ll res=1,tmp=a;
	for(;b;tmp=tmp*tmp%mod,b>>=1)
		if(b&1) res=res*tmp%mod;
	return res;
}
ll work(int n,int m)
{
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main()
{
	fac[0]=1;for(int i=1;i<=N;++i) fac[i]=fac[i-1]*i%mod;
	
	inv[N]=fast_pow(fac[N],mod-2);
	for(int i=N-1;i>=0;--i)
	inv[i]=(i+1)*inv[i+1]%mod;
	scanf("%d%d%d%d",&h,&w,&a,&b);
	a=h-a;b++;
	ll ans=0;
	for(int i=1;i<=a;++i) ans=(ans+work(b+i-3,b-2)*work(h-i+w-b,h-i)%mod)%mod;
	cout<<ans;
}

Measured memory_bytes: 3456
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)


int main(){
	ll a,b;
	cin>>a>>b;
	cout<<__gcd(a,b)<<endl;
}

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

#define REP(i, n) for(int i = 0; i < (int)n; ++i)

using namespace std;

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

    int N, M;
    cin >> N >> M;
    int L_max = 0;
    int R_min = 1000000;
    REP(i, M) {
        int L_i, R_i;
        cin >> L_i >> R_i;
        L_max = max(L_i, L_max);
        R_min = min(R_i, R_min);
    }
    if (R_min - L_max < 0) cout << 0 << '\n';
    else cout << R_min - L_max + 1 << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main( void ) {
	int n, sum;
	char ch[ 9 ][ 6 ] = { ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" }, key, tmp;

	for ( scanf( "%d ", &n ); n--; putchar( '\n' ) )
		while ( ( key = getchar() ) != '\n' ) {
			if ( key == '0' )
				continue;

			for ( sum = 0; ( tmp = getchar() ) != '0'; sum++ ) ;

			putchar( ch[ key - '1' ][ sum % strlen( ch[ key - '1' ] ) ] );
		}

	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define BIGINF (int) 4e18 + 7
#define MOD7 1000000007
#define MOD9 1e9 + 9
#define INF  (int)2e9 + 7
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long ll;
typedef long double ld;
typedef string str;
typedef double d;
typedef unsigned u;
typedef unsigned long long ull;

int main () {
	//#ifndef ONLINE_JUDGE
		//freopen("inputf.txt", "r", stdin);
		//freopen("outputf.txt", "w", stdout);
	//#endif
	ll n, k;
	SCLLD(n);
	SCLLD(k);
	if (n == 0) { printf("0");}
	else {
		long long ans = n % k;
		ans = min (ans, abs(ans - k));
		printf("%lld", ans);
	}	
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<stack>
#include<map>
int f(int n){
    int num=0;
	if(n%2!=0)
		return 0;
	else{
		while(n&&n%2==0){
			n=n/2;
			num++;
		}
		return num;
	}
}
using namespace std;
int main(){
	int n,a[1000];
	cin>>n;
	for(int i=1;i<=n;i++){
		int m;
		cin>>m;
		a[i]=f(m);
	}
	sort(a+1,a+1+n);
	printf("%d\n",a[1]);
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a, b;
  char op;


  while(1){
	scanf("%d %c %d", &a, &op, &b);
	if(op == '?'){break;}
	switch(op){
	case '+':
	  printf("%d\n", a + b);
	  break;
	case '-':
	  printf("%d\n", a - b);
	  break;
	case '*':
	  printf("%d\n", a * b);
	  break;
	case '/':
	  printf("%d\n", a / b);
	  break;
	default:
	  break;
	}
  }
  return 0;

}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll INF = 1LL << 58;

//xより以下の要素へのindex
template <class T> int former(const vector<T> &v, T x) {
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素へのindex
template <class T> int latter(const vector<T> &v, T x) {
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}

int comb(int n,int k){
    int ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<pair<int,int> > x(n+1);
    vector<int> ans(n+1);
    FOR(i,1,n+1){
        int k;
        cin>>k;
        x[i]=make_pair(k,i);
    }
    sort(x.begin(),x.end());
    int a=x[n/2].first;
    int b=x[n/2+1].first;
    FOR(i,1,n+1){
        auto itr=x.begin()+i;
        if(i<=n/2){
            ans[itr->second]=b;
        }else{
            ans[itr->second]=a;
        }
    }
    FOR(i,1,n+1){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 4608
import java.util.*;
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Random rand = new Random();
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = -1;
        for(int i = 10000; i > 0; i--){
            int tax1 = (int)(i* 0.08);
            int tax2 = (int)(i* 0.1);
            if(tax1==a && tax2==b){
                ans = i;
            }
        }
        System.out.println(ans);

    
	}
}

Measured memory_bytes: 23252
from collections import deque
import copy
H,W= map(int, input().split())
c=[list(input()) for i in range(H)]

max_num=0
move=[[0,1],[0,-1],[1,0],[-1,0]]
for h in range(H):
    for w in range(W):
        if c[h][w]=='.':
            #初期位置#(H,W)
            L=copy.deepcopy(c)
            d=deque([[h,w]])
            L[h][w]='S'

            num=0
            while d:
                num+=1
                for i in range(len(d)):
                    q=d.popleft()
                    for m in move:
                        if 0<=q[0]+m[0]<=H-1 and 0<=q[1]+m[1]<=W-1 and L[q[0]+m[0]][q[1]+m[1]]=='.':
                            L[q[0]+m[0]][q[1]+m[1]]=num

                            d.append([q[0]+m[0],q[1]+m[1]])

           # print(num-1)
            if num-1>=max_num:
                max_num=num-1
print(max_num)

Measured memory_bytes: 9564
#include<iostream>
#include<fstream>
#include<string>
#include<algorithm>
using namespace std;
long int a,b,c,sum;
long int f[1000];
int main()
{
 cin>>a>>b>>c;
 for(int i=0; i<a; i++)
 cin>>f[i];
 for(int i=0; i<a; i++)
 {
 	if(f[i]<b or f[i]>=c)
 	sum++;
 }
 cout<<sum<<endl;
 return 0;
}


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

int main()
{
    int N, K, X, Y, sum ;
    cin >> N >> K >> X >> Y ;
    
    if( N <= K )
    sum = X*N ;
    else
    sum = (X*K)+Y*(N-K) ;

    cout << sum << '\n' ;    

    return 0 ;
} 

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

int main() {
	int d;
	while (cin >> d) {
		int s = 0;
		for (int i = d; i <= (600 - d); i+=d) {
			s += pow(i, 2)*d;
		}
		cout << s << endl;
	}
}


Measured memory_bytes: 3072
from sys import stdin
def main():
    readline=stdin.readline
    N,P=map(int,readline().split())
    S=readline().strip()
    r=[0]*(N+1)

    if P!=2 and P!=5:
        now=1
        for i in range(N):
            a=(int(S[N-i-1])*now)%P
            r[i+1]=(a+r[i])%P
            now*=10
            now%=P
        
        d=dict()
        for n in range(P):
            d[str(n)]=0
        d["0"]=1

        ans=0
        for i in range(1,N+1):
            ans+=d[str(r[i])]
            d[str(r[i])]+=1
            
        print(ans)

    elif P==2 or P==5:
        ans=0
        for i in range(N-1,-1,-1):
            if int(S[i])%P==0:
                ans+=i+1

        print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 11956
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define ll            long long

#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void sb()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int main()
{
	//sb();
int k;
int a,b;
cin>>k>>a>>b;
if(a>b)
swap(a,b);
int check = (b/k)*k;
//cout<<check<<" ";
if(check>=a && check<=b)
cout<<"OK";
else
cout<<"NG";
	

return 0;
}



Measured memory_bytes: 3588
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,x) for(int i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 1001001001;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

int main() {
    string s;
    cin >> s;
    ll size = s.size();
    ll ans = 0;
    for (int i = 1; i < size; i++) {
        if (s[i] == s[i - 1]) {
            ans++;
            if (s[i] == '0')s[i] = '1';
            else s[i] = '0';
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
# coding: utf-8
# Your code here!
N,X=map(int,input().split())

X-=1
def saiki(i,x,count):
    if i==-1:
        print(int(count)+1)
        exit()
    all=2**(i+2)-3
    paty=2**(i+1)-1
    if x==all-1:
        print(count+paty)
        exit()
    elif x==0:
        print(count)
    elif x==(all-1)//2:
        print(int(count+(paty-1)//2+1))
        exit()
    elif x>(all-1)//2:
        count+=((paty-1)//2+1)
        x-=(all//2)
        saiki(i-1,x-1,count)
    elif x<(all-1)//2:
        saiki(i-1,x-1,count)
    

ans=0
saiki(N,X,ans)



Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <tuple>
#include <cstring>

using namespace std;
typedef tuple<int, int, int> tiii;
static const double EPS = 1e-8;
static double dp[201][201];

int main(){
	ios_base::sync_with_stdio(false);
	cout << setiosflags(ios::fixed) << setprecision(10);
	int n, m;
	cin >> n >> m;
	vector<vector<tiii>> pots;
	for(int i = 0; i < n; ++i){
		int k;
		cin >> k;
		vector<tiii> shape;
		for(int j = 0; j < k; ++j){
			int s, h;
			cin >> s >> h;
			shape.emplace_back(s, h, i);
		}
		pots.push_back(shape);
	}
	memset(dp, 0, sizeof(dp));
	for(int i = 0; i < n; ++i){
		vector<double> htable(m + 1);
		for(int j = 0, k = 0; k < m && j < pots[i].size(); ++j){
			const int limit = get<0>(pots[i][j]) * get<1>(pots[i][j]);
			for(int l = 0; l < limit && k < m; ++k, ++l){
				htable[k + 1] = htable[k] + 1.0 / get<0>(pots[i][j]);
			}
		}
		for(int j = 0; j <= m; ++j){
			for(int k = 0; k + j <= m; ++k){
				dp[i + 1][j + k] = max(dp[i + 1][j + k], dp[i][j] + htable[k]);
			}
		}
	}
	double answer = 0.0;
	for(int i = 0; i <= m; ++i){
		answer = max(answer, dp[n][i]);
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 1632
n, m = map(int,input().split())
h = list(map(int,input().split()))
bads = set()
ans = n
for i in range(m):
  a, b = map(int,input().split())
  a -= 1 #hが0からのため
  b -= 1
  if a not in bads and h[a] <= h[b]:
    bads.add(a)
    ans -= 1
  if b not in bads and h[a] >= h[b]:
    bads.add(b)
    ans -= 1
print(ans)

Measured memory_bytes: 20104
#include<iostream>
using namespace std;
int main(){
    int n,m,l,num;
    cin>>n>>m>>l;
    int A[n][m],B[m][l];
    for (int a=0;a<n;a++){
        for (int b=0;b<m;b++){
            cin>>num;
            A[a][b]=num;
        }
    }for (int a=0;a<m;a++){
        for (int b=0;b<l;b++){
            cin>>num;
            B[a][b]=num;
        }
    }long long sum=0;
    for (int a=0;a<n;a++){
        for (int c=0;c<l;c++){
            for(int b=0;b<m;b++){
                sum=sum+A[a][b]*B[b][c];
            }cout<<sum;
            sum=0;
            if(c!=l-1) cout<<" ";
        }cout<<endl;
    }return 0;
}


Measured memory_bytes: 3148
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    i64 N, K;
    read(N, K);

    vector<i64> d;

    while (N > 0) {
        d.push_back(N % K);
        N /= K;
    }

    print(d.size());


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int i,n;cin>>n;
  vector<int> a(n),b(n);
  for(i=0; i<n; ++i) cin>>a[i]>>b[i];
  sort(a.begin(),a.end()), sort(b.begin(),b.end());
  int cnt=0;
  if(n%2==1) cnt=b[(n+1)/2-1]-a[(n+1)/2-1]+1;
  else cnt=(b[n/2-1]+b[n/2])-(a[n/2-1]+a[n/2])+1;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 4772
#include<stdio.h>

int main()
{
   int n, d, x, i, j, asum, nd;                                                                                                             
   nd = j = 1;
   asum = 0;
   int a[100],count[100];

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


   for(i=0;i<n;i++){
      scanf("%d",&a[i]);
   }

   for(i=0;i<n;i++){
      count[i] = 0;
      while(nd <= d){
         count[i]++;
         nd = j * a[i] + 1;
         j++;
      }
      nd = j = 1;
   }


   for(i=0;i<n;i++){
      asum += count[i];
   }

   printf("\n%d\n",asum + x);

   return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int sx = 0, sy = 0;
    int w, h, n; cin >> w >> h >> n;
    rep(i, n) {
        int x, y, a; cin >> x >> y >> a;
        if (a == 1) chmax(sx, x);
        else if (a == 2) chmin(w, x);
        else if (a == 3) chmax(sy, y);
        else if (a == 4) chmin(h, y);
    }
    int ans = (w - sx) * (h - sy);
    if ((w - sx) < 0 || (h - sy) < 0) ans = 0;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
an=$stdin.read.split(/\s/).map(&:to_i)
an.shift
l = {}
r = {}
an.each.with_index(1) do |a,i|
  l[a+i] ||= []
  l[a+i] << i
  r[i-a] ||= []
  r[i-a] << i
end

res = 0
l.each do |v,x|
  if r[v]
    res += x.count * r[v].count
  end
end


puts res

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

int N;
list<int> E[100010];
int P[100010];
int color[100010];
const int FENNEC = 0, SNUKE = 1;

void dfs(int u) {
  for (int v : E[u]) {
    if (P[v] == -1) {
      P[v] = u;
      dfs(v);
    }
  }
}

void fill_color(int u) {
  if (color[u] != -1) return;
  fill_color(P[u]);
  color[u] = color[P[u]];
}

int main() {
  cin >> N;
  for (int i = 0 ;i < N-1; i++) {
    int a, b; cin >> a >> b;
    a--;b--;
    E[a].push_back(b); E[b].push_back(a);
  }
  for (int i = 0; i < N; i++) { P[i] = -1; color[i] = -1; }
  P[0] = 0;
  dfs(0);
  vector<int> V;
  int u = N-1, I = 0; for (; u != 0; I++) { u = P[u]; V.push_back(u); }
  for (int i = 0; i <= I/2; i++) { color[V.back()] = FENNEC; V.pop_back(); }
  for (int v : V) { color[v] = SNUKE; }
  color[N-1] = SNUKE;
  for (int i = 0; i < N; i++) fill_color(i);
  int snuke_cnt = 0;
  for (int i = 0; i < N; i++) snuke_cnt += (color[i] == SNUKE);
  if (N - snuke_cnt > snuke_cnt) cout<<"Fennec"<<endl;
  else cout << "Snuke"<<endl;
}

Measured memory_bytes: 17872
#include <stdio.h>		// standard input output
#include <iostream>		// input output stream, cin cout( console in console out)
#include <cmath>		// circle math ( sin, con, sinh
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>		// input output manipulation
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long 
int main() {
  int X,Y; // 変数の宣言
  cin >> X >> Y; // 標準入力
  
  int N=0;
  for(int i=0;i<X+1;i++){
    if((2*N + 4*(X-N)) == Y){
      cout << "Yes" << endl;
      return 0;
    }
    N++;
  }
  cout << "No" << endl;

}



Measured memory_bytes: 3088
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

void printVector(const std::vector<double>& vec) {
    for (double value : vec) {
		std::cout << value << " ";
    }
	std::cout << std::endl;
}

int main(){
	int n,m,x;
	std::cin >> n >> m >> x;
	// std::vector<std::vector<int>> a;
	int a[20][20] = {0};
	for ( int i = 0 ; i < n ; i++ ) {
		for ( int ii = 0 ; ii < m+1 ; ii++ ) {
			int gomi;
			std::cin >> gomi;
			a[i][ii] = gomi;
		}
	}

	int min_cost = INT_MAX;
	// {0, 1, ..., n-1} の部分集合の全探索
	for (int bit = 0; bit < (1<<n); ++bit)
	{
		/* bit で表される集合の処理を書く */
		std::bitset<20> b = std::bitset<20>(bit);
		int cost = 0;
		int kijun[20] = {0};
		bool flag = true;

		for ( int i = 0 ; i < n ; i++ ) {
			if(b[i]){
				cost += a[i][0];
				for ( int ii = 0 ; ii < m ; ii++ ) {
					kijun[ii] += a[i][ii+1];
				}
			}
		}
		for ( int i = 0 ; i < m ; i++ ) {
			if ( kijun[i] < x ) flag = false;
		}
		if(flag && min_cost > cost) min_cost = cost;

	}
	if (min_cost == INT_MAX) min_cost = -1;
	std::cout << min_cost << std::endl;
	return 0;
}


Measured memory_bytes: 3572
#include <cstdio>
#include <utility>

const char* solve() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if (a == b && a != c) { return "Yes"; }
  if (a == c && a != b) { return "Yes"; }
  if (b == c && b != a) { return "Yes"; }
  return "No";
}

int main() {
  printf("%s\n", solve());
  return 0;
}

Measured memory_bytes: 128
from collections import defaultdict
from heapq import heappop, heappush
class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]

def solve():
  n,m = (int(i) for i in input().split())
  route = Graph()
  tmp = [[0]*n for _ in range(n)]
  
  for i in range(m):
    a,b,c = (int(i) for i in input().split())
    route.add_edge(a-1,b-1,c)
    route.add_edge(b-1,a-1,c)
    tmp[a-1][b-1] = 1

  
  for i in range(n):
    #iを始点としてjに着く経路
    ds = Dijkstra(route,i)
    for j in range(n):
      if not i== j:
        query = ds.shortest_path(j)
        for k in range(len(query)-1):
            tmp[query[k]][query[k+1]] = 0
  ans = 0
  for i in range(n):
    ans += sum(tmp[i])
  print(ans)
        
solve()

Measured memory_bytes: 61020