akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
int main(){
  int n,k;
  scanf("%d",&n);
  char s[n + 1],c[n + 1];
  scanf("%s %s",&s,&c);
  for(int i = n;i > 0;i--){
    k = 1;
    for(int j = 0;j < i;j++){
      if(s[n - i + j] != c[j]){
        k = 0;
      }
    }
    if(k){
      printf("%d\n",2 * n - i);
      return 0;
    }
  }
  printf("%d\n",2 * n);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main()
{
	int a[101]={0},b,max=0;
	while(scanf("%d",&b)!=EOF)
		a[b]++;
	for(int i=1;i<=100;i++){
		if(max<a[i])
			max=a[i];
	}
	for(int i=1;i<=100;i++){
		if(max==a[i])
			printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <map>

#define AS(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
long long int MOD = 1000000007;
long long int INF = 10000000007;

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

int main() {
    int N;
    cin >> N;
    if(N % 10 == 9 || N / 10 == 9) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

int main(){
  
  int h,n; cin >> h >> n;
  vector<int> a(n); rep(i,n) cin >> a[i];

  int s = 0;
  rep(i,n){
    s += a[i];
  }

  cout << (s >= h?"Yes":"No") << endl;
  
}


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

string s;
int l,r,num;

int main()
{
	ios::sync_with_stdio(false);
	cin>>s;
	l=0;r=s.length()-1;
	while(l<=r){
		if(s[l]==s[r]){
			l++;
			r--;
			continue;
		}
		if(s[l]=='x'){
			l++;
			num++;
			continue;
		}
		if(s[r]=='x'){
			r--;
			num++;
			continue;
		}
		puts("-1");
		return 0;
	}
	printf("%d\n",num);
	return 0;
}

Measured memory_bytes: 512
S = input()[::-1]
A = ["maerd","remaerd","esare","resare"]
def HIT(ST,A):
  for i in A:
    if ST[:len(i)]==i:
      return ST[len(i):]
    else:
      continue
  return ST
for j in range(len(S)//5+1):
  S = HIT(S,A)
  if S == "":
    break
if S == "":
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3188
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] line = new int[5];
		boolean check = true;
		for(int i = 0; i < 5; i++) {
			line[i] = sc.nextInt();
		}
		int k = sc.nextInt();
		ArrayList<Integer> lis = new ArrayList<>();
		for(int i = 0; i < 5; i++) {
			for(int j = i+1; j < 5; j++) {
				if(Math.abs(line[i]-line[j]) > k) {
					check = false;
					break;
				}
			}
		}
		if(check)System.out.println("Yay!");
		else System.out.println(":(");
	}
}

Measured memory_bytes: 22868
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#define Pll make_pair
using namespace std;
typedef long long ll;
const int MAXN=2e5+50;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int phi=1e9+6;
int a[MAXN],sum[MAXN];
int main()
{
    int n,k;
    cin>>n>>k;
    int x;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum[i]=sum[i-1]+a[i];
    }
    int ma=-99;
    for(int i=1;i+k-1<=n;i++){
        if(sum[i+k-1]-sum[i-1]>ma){
            ma=sum[i+k-1]-sum[i-1];
            x=i;
        }
    }
    double ans=0;
    for(int i=x;i<=x+k-1;i++){
        ans+=((a[i]+1.0)/2.0);
    }
    printf("%.10lf\n",ans);
    return 0;
}
/*

 */

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>

using namespace std;

typedef long long ll;

const ll prime = 10000000000 + 7;

int main() {
	
	ll n, k, q;
	cin >> n >> k >> q;
	vector<ll> a(q);
	for (ll i = 0; i < q; i++)
	{
		cin >> a[i];
	}
	
	vector<ll> b(n, k - q);

	for (ll i = 0; i < q; i++)
	{
		b[a[i] - 1]++;
	}

	for (ll i = 0; i < n; i++)
	{
		if (b[i] <= 0) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 2176
import math
def main():
  N = int(input())
  t = input().split(" ")
  a = []
  for i in range(N):
    ii = int(t[i])
    a.append(ii-i-1)
  a.sort()
  if N % 2 == 0:
    t = (a[N//2-1] + a[N//2])//2
  else:
    t = a[(N-1)//2]
  b = 0
  c = 0
  for i in range(N):
  	b += abs(a[i] - t)
  	c += abs(a[i] - t - 1)
  if c < b:
    print(c)
  else:
    print(b)
main()


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

const long long N = 2e5+5;
vector<long long> v[N];
long long val[N];

void dfs(long long w, long long p) {
    for (long long i : v[w]) {
        if (i == p) continue;
        val[i] += val[w];
        dfs(i, w);
    }
}

int main() {
    long long n, q; cin >> n >> q;
    rep(i,n-1) {
        long long x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    while (q--) {
        long long x, y;
        cin >> x >> y;
        val[x] += y;
    }
    dfs(1,0);
    for (int i=1; i<=n; ++i) cout << val[i] << " ";
    cout << endl;
    return 0;

}

Measured memory_bytes: 24320
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	int k;
	cin>>n;
	cin>>k;
	const int INF=1e9+3;
	int a[n+1];
	int dp[n+1];
	for (int i = 1; i <=n; ++i)
	{
		cin>>a[i];
	}
	dp[1]=0;
	for (int i = 2; i <=n; ++i)
	{
		dp[i]=INF;
		for(int j=1;j<=k;j++)
		{
			if(i-j<1)
				break;

			dp[i]=min(dp[i],abs(a[i]-a[i-j])+dp[i-j]);
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  rep(i,n){
    ll a;cin>>a;
    if(a%2==0&&(a%3)*(a%5)){
      cout<<"DENIED"<<endl;
      return 0;
    }
  }
  cout<<"APPROVED"<<endl;
  return 0;

}


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

#define ll long long
using namespace std;

int main()
{
    ll n,m; cin>>n>>m;

    bool is_correct[n+1]= {false};
    int W[n+1]{};
    ll correct=0;
    ll wrong = 0;

    for(int i = 0 ; i< m ; i++)
    {
    ll problem;
    string verdict;
    cin>>problem>>verdict;
    if(is_correct[problem]==false && verdict=="WA" )
        W[problem]++;
    else if(is_correct[problem]==false && verdict=="AC" )
    {
        correct++;
        is_correct[problem]=true;
        wrong+=W[problem];
    }
    }
    cout<<correct<<" "<<wrong<<endl;
}


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

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

    if(N == 2) {
        if(K == 0) cout << "1\n1 2" << endl;
        else cout << -1 << endl;
        return 0;
    }

    if(K > (N - 1) * (N - 2) / 2) {
        cout << -1 << endl;
        return 0;
    }

    cout << N * (N - 1) / 2 - K << endl;
    for(int i=2; i<=N; ++i) {
        cout << "1 " << i << endl;
    }
    int m = (N - 1) * (N - 2) / 2 - K;
    for(int i=2; i<=N; ++i) {
        for(int j=i+1; j<=N; ++j) {
            if(m == 0) return 0;
            cout << i << ' ' << j << endl;
            --m;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
 
/*** Template Begins ***/
 
typedef long long    ll;
typedef pair<ll,ll>  pll;
typedef pair<ll, pair<int, int> > plll;
typedef vector<long long>  vll;
typedef vector<pll>  vp;
typedef long double ld;
#define pb           push_back
#define INF          INT_MAX/10
#define F            first
#define S            second
#define mp           make_pair
#define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell         1000000007
// #define h 998244353
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p){ ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;} return res; } 
 
// Debug //
 
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
// #define trace6(a, n,i;b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

// Constants //
 
/*** Template Ends ***/
bool comp(string a,string b)
{
  return a.length()<b.length();
}
void solve()
{
  ll n,k;
  cin>>n>>k;
  ll a;
  ll ans=0,i;
  for(i=0;i<n;i++)
  {
    cin>>a;
    if(a>=k)
      ans++;
  }
  cout<<ans;   
}
int main()
{ 
  ios;
  // fxreopen("inputt.txt", "w", stdout);
  ll t;
  // cin >> t;
  t=1;
  while(t--)
    solve();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n, x, t, i;
    scanf("%d %d %d", &n, &x, &t);

    for(i = 1; i <= n; i++)
    {
        if(x*i >= n)
        {
            break;
        }
    }
    printf("%d\n", i*t);

    return 0;
}

Measured memory_bytes: 1704
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );
	final int n = Integer.parseInt( stdin.nextLine() );

	for ( int t = 1; t <= n; t++ ) {
	    stdin.nextLine();
	    char[][] map = new char[8][];
	    for ( int j = 0; j < 8; j++ ) {
		map[j] = stdin.nextLine().toCharArray();
	    }
	    final int x = Integer.parseInt( stdin.nextLine() ) - 1;
	    final int y = Integer.parseInt( stdin.nextLine() ) - 1;

	    dfs( map, y, x );
	    System.out.printf( "Data %d:\n", t );
	    for ( int i = 0; i < map.length; i++ ) {
		for ( int j = 0; j < map[i].length; j++ ) {
		    System.out.print( map[i][j] );
		}
		System.out.println();
	    }
	}	
    }

    static void dfs( char[][] map, int y, int x ) {

	map[y][x] = '0';
	
	final int minX = max( x - 3, 0 );
	final int maxX = min( x + 3, 7 );
	final int minY = max( y - 3, 0 );
	final int maxY = min( y + 3, 7 );

	for ( int i = minX; i <= maxX; i++ ) {
	    if ( map[y][i] == '1' ) {
		dfs( map, y, i );
	    }
	}
	for ( int i = minY; i <= maxY; i++ ) {
	    if ( map[i][x] == '1' ) {
		dfs( map, i, x );
	    }
	}	
    }    
}

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

int main(){
    
    int ans = 0;
    for(int i = 0; i < 5; ++i){
        int y; cin >> y;
        if( y == 0 ) ans = i + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

#define INF 123456789

struct edge {
  int from;
  int to;
  int cost;
};

vector<int> to_from[2505];
vector<int> from_of_to[2505];
bool reachable_from_s[2505];
bool reachable_to_g[2505];
bool reachable[2505];

void dfsFromS(int v) {
  if (reachable_from_s[v]) { return; } // already reached.

  reachable_from_s[v] = true;
  for (int u : to_from[v]) {
    dfsFromS(u);
  }
}

void dfsFromG(int v) {
  if (reachable_to_g[v]) { return; } // already reached.

  reachable_to_g[v] = true;
  for (int u : from_of_to[v]) {
    dfsFromG(u);
  }
}

int main(int argc, char** argv) {
  // N .. vertex
  // M .. edge
  // P .. cost offset
  int N, M, P;
  cin >> N >> M >> P;
  vector<edge> edges;
  rep(i, M) {
    edge e;
    cin >> e.from >> e.to >> e.cost;
    --e.from; // Convert index from [1, N] to [0, N-1].
    --e.to;   // Convert index from [1, N] to [0, N-1].
    e.cost = - (e.cost - P);
    edges.push_back(e);
    to_from[e.from].push_back(e.to);
    from_of_to[e.to].push_back(e.from);
  }

  // For Debug
  // rep(i, M) {
  //   cout << edges[i].from << ", " << edges[i].to << ", " << edges[i].cost << endl;
  // }

  dfsFromS(0);  // For initialization of reachable_from_s
  dfsFromG(N - 1);  // For initialization of reachable_to_g
  rep(i, N) {  // For initialization of reachable
    reachable[i] = reachable_from_s[i] && reachable_to_g[i];
  }

  // NOTE: We focus only reachable vetices.

  bool negative_existence = false;
  vector<int64_t> d(N, INF);  // Initialize with INF.
  d[0] = 0;  // Set 0 to start point.
  rep(i, N) {
    rep(j, M) {
      edge e = edges[j];
      if (d[e.to] > d[e.from] + e.cost) {
        if (!reachable[e.from]) { continue; }
        if (!reachable[e.to]) { continue; }

        d[e.to] = d[e.from] + e.cost;

        // For Deubg
        // cout << i << " loop: " << endl;
        // rep(i, N) {
        //   if (d[i] == INF) {
        //     cout << "INF ";
        //   } else {
        //     cout << d[i] << " ";
        //   }
        // }
        // cout << endl;

        if (i == N - 1) { // Check loop count. if reached to N times, it means the existence of loop.
          negative_existence = true;
          break;
        }
      }
    }
  }

  if (negative_existence) {
    cout << -1 << endl;
  } else if (d[N - 1] == INF) { // Goal can't be reached.
    cout << -1 << endl;
  } else {
    int r = -d[N - 1];
    cout << max(0, r) << endl;
  }

  return 0;
}


Measured memory_bytes: 640
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	M = 0
	for i in range(2, 10 ** 3):
		if i * (i - 1) == 2 * N:
			M = i - 1
			break

	if M == 0:
		print("No")
		return

	print("Yes")
	print(M + 1)

	L = []
	cnt = 1
	for i in range(M):
		l = []
		for j in range(i + 1):
			l.append(cnt)
			cnt += 1
		L.append(l)


	ans = [M]
	for i in range(M):
		ans.append(L[i][-1])
	print(*ans)

	for i in range(M):
		ans = [M]
		for j in range(i + 1):
			ans.append(L[i][j])
		for j in range(i + 1, M):
			ans.append(L[j][i])
		print(*ans)


if __name__ == '__main__':
	main()

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

int F,C;			//変数の用意

int main(){
cin>>F;		 	//変数の読み込み
C = ( F -30 ) / 2;		//華氏温度（F）を摂氏温度（C）に変換
cout<< C << endl; 	//合計金額が安い方を出力

return 0;
}



Measured memory_bytes: 3116
import sys

n,m = map(int,input().split())
ans = [0]*n
l = []
for i in range(m):
    s,c = map(int,input().split())
    l.append([s,c])
for i in l:
    if i[0] == 1 and i[1] == 0 and n != 1:
        print(-1)
        sys.exit()
    if ans[i[0]-1] != 0 and ans[i[0]-1] != i[1]:
        print(-1)
        sys.exit()
    ans[i[0]-1] = i[1]

if ans[0] == 0 and n != 1:
    ans[0] = 1
t = ""
for i in ans:
    t += str(i)
print(int(t))

Measured memory_bytes: 3064
s = input()

if s == 'SUN':
    print('7')
elif s == 'MON':
    print('6')
elif s == 'TUE':
    print('5')
elif s == 'WED':
    print('4')
elif s == 'THU':
    print('3')
elif s == 'FRI':
    print('2')
elif s == 'SAT':
    print('1')

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  int ac=0;
  int wa=0;
  int tle=0;
  int re=0;
  vector<string> v(n);
  for(int i=0;i<n;i++) cin >> v[i];
  for(int i=0;i<n;i++){
    if(v[i]=="AC") ac++;
    else if(v[i]=="WA") wa++;
    else if(v[i]=="TLE") tle++;
    else re++;
  }
  cout << "AC x " << ac << "\n" << "WA x " << wa <<  "\n" << "TLE x " << tle << "\n" << "RE x " << re << "\n";
  return 0;
}

Measured memory_bytes: 6324
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String line[] = br.readLine().split(" ");
		int n = Integer.parseInt(line[0]);
		int k = Integer.parseInt(line[1]);
		line = br.readLine().split(" ");
		br.close();
		
		List<Integer> nums = new ArrayList<Integer>();
		nums.add(0);
		for(int i=0;i<n;i++) {
			nums.add(Integer.parseInt(line[i]));
		}
 
		List<Double> result = new ArrayList<Double>();
//		for(int i=0;i<n-k+1;i++) {
//			double res = 0.000000f;
//			for(int l=i;l<i+k;l++){
//				double s = (1.000000f + nums.get(l))/2;
//				res = res + s;
//			}
//			result.add(res);
//		}
		List<Double> sum = new ArrayList<Double>();
		// しょきち
		sum.add(0.000000);
		for(int i=1;i<n+1;i++) {
			double e = (1.000000 + nums.get(i))/2;
			double pre = sum.get(i-1);
			sum.add(pre+e);
		}
		result.add(sum.get(k)-sum.get(0));
		for(int i=1;i<n-k+1;i++) {
			result.add(sum.get(i+k)-sum.get(i));
		}
		System.out.println(Collections.max(result));
	}

}


Measured memory_bytes: 60172
n = int(input())
w = list(map(int, input().split()))
ans = 10000
for i in range(1, n) :
    l = 0
    r = 0
    for j in range(0, i) :
        l += w[j]
    for j in range(i, n) :
        r += w[j]
    ans = min(ans, abs(l-r))
print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    char[] S = sc.next().toCharArray();
    char[] T = sc.next().toCharArray();
    StringBuilder sb = new StringBuilder();
    for(int i=0; i<N; i++){
      sb.append(S[i]);
      sb.append(T[i]);
    }
    System.out.print(sb.toString());
  }
}
      


Measured memory_bytes: 21460
# -*- coding: utf-8 -*-
import itertools
import math

N, D = map(int, input().split())

X = [[0 for x in range(D)] for y in range(N)]

for n in range(N):
    X[n] = list(map(int, input().split()))

ans = 0
for target in itertools.combinations(X, 2):
    res = sum([abs(y - z) ** 2 for y, z in zip(target[0], target[1])])

    res = math.sqrt(res)
    if res.is_integer():
        ans += 1

print(ans)


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

int main(){
  int N, ans = 0, cnt = 0;
  int a[2][100] = {};

  cin>>N;
  for(int i=0;i<=1;i++){
    for(int j=0;j<N;j++){
      cin>>a[i][j];
    }
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<=i;j++){
      cnt += a[0][j];
    }
    for(int k=i;k<N;k++){
      cnt += a[1][k];
    }
    if(ans < cnt) ans = cnt;
    cnt = 0;
  }

  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N_MAX 1000100
using namespace std;
int cont=1;
bool cb[N_MAX];
typedef long long ll;
vector<int> divi;
int mat[N_MAX];
void criba(){
	divi.assign(N_MAX,-1);
	memset(cb,0,sizeof cb);
	for(int i = 2; i < N_MAX; i++)
		if(!cb[i]){
			cont++;
			if((ll)i*i >= N_MAX)
				continue;
			for(int j = i*i; j < N_MAX; j += i){
				cb[j] = 1;
				divi[j] = i;
			}
		}
}
int main(){
	criba();
	int n;
	scanf("%d",&n);
	vector<int> v(n);
	for(int& x : v)
		scanf("%d",&x);
	int gcd = v[0];
	for(int x : v)
		gcd = __gcd(gcd,x);
	bool sw = 1;
	for(int x : v){
		while(x > 1){
			int y;
			if(divi[x] == -1)
				y = x;
			else
				y = divi[x];
			if(mat[y]){
				sw = 0;
				break;
			}
			mat[y]++;
			while(x%y == 0)
				x = x/y;
		}
		if(!sw)
			break;
	}
	if(!sw){
		if(gcd == 1)
			printf("setwise coprime\n");
		else
			printf("not coprime\n");		
	}
	else
		printf("pairwise coprime\n");
	return 0;
}

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

int main() {
  int N,A,B;
  cin>>N>>A>>B;
  vector<int64_t> p(N);
  for(int i=0;i<N;i++){
    cin>>p[i];
  }
  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  int X=0;
  for(int i=1;i<A;i++){
    if(p[i]!=p[i-1]){
      X=i;
    }
  }
  int64_t Z=0,ans=1;
  for(int i=0;i<A;i++){
    Z+=p[i];
  }
  double potato=Z;
  potato/=A;
  cout<<fixed<<setprecision(20);
  cout<<potato<<endl;
  if(X){
    int S=A;
    while(S<N){
      if(p[S]!=p[S-1]){
        break;
      }
      S++;
    }
    S-=A;
    for(int i=0;i<S;i++){
      ans*=(A-X+S-i);
      ans/=(i+1);
    }
  }
  else{
    int S=A;
    while(S<N){
      if(p[S]!=p[S-1]){
        break;
      }
      S++;
    }
    ans--;
    for(int i=A;i<=min(B,S);i++){
      int64_t L=1;
      for(int j=0;j<i;j++){
        L*=(S-j);
        L/=(j+1);
      }
      ans+=L;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3828
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

int main(void){
    ll a,b,k;
    cin>>a>>b>>k;
    if(a>=k)cout<<a-k<<" "<<b<<endl;
    else{
        cout<<0<<" ";
        k-=a;
        if(b>=k)cout<<b-k<<endl;
        else cout<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>


#define rep(i,p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

//130 B
int main(void) {
	int n, x;
	int pos = 0;
	int ans = 0;
	cin >> n >> x;
	if (pos <= x)ans++;
	rep(i, 0, n) {
		int l = 0;
		cin >> l;
		pos = pos + l;
		if (pos <= x)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const char S[]={"keyence"};
char a[N];
int main()
{
    scanf("%s",a);
    int cur=0,n=strlen(a);
    if(n==7){
        if(strcmp(a,S)==0){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }else if(n>7){
        for(int i=0;i<n;i++){
            if(a[i]!=S[cur]){
                break;
            }else{
                cur++;
            }
        }
        //printf("cur   : %d\n",cur);
        for(int i=n-(7-cur);i<n;i++){
            if(a[i]!=S[cur]){
                break;
            }else{
                cur++;
            }
        }
        if(cur==7){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }else{
        printf("NO\n");
    }
    return 0;
}


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

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, 0, N) cin >> A[i];
    int inc = 0;
    ll ans = 1;
    rep(i, 0, N-1){
        if(inc == -1){
            if(A[i] < A[i+1]){
                ans++;
                inc = 0;
            }
        }else if(inc == 1){
            if(A[i] > A[i+1]){
                ans++;
                inc = 0;
            }
        }else{
            if(A[i] > A[i+1]) inc = -1;
            else if(A[i] < A[i+1]) inc = 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;cin>>n;
    string x;
    int a,b;
    cin>>a>>b;
    int s;
    ull ans=0;
    for (int i=1;i<=n;i++){
        s=0;
        x=to_string(i);
        for (char j:x){
            s+=j-'0';
        }if (s>=a&&s<=b){
            ans+=i;
        }
    }cout<<ans;
    return 0;
}

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

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	int g = 0, p = 0;
	for (int i = 0; i < (int)(s.length()); i++) {

		if (s[i] == 'g') g++;
		else p++;
	}

	int ch = s.length() / 2;

	if (g > ch) cout << ch - p;
	else cout << p - ch;

	return 0;
}

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

using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int,int>
#define mii map<int,int>
#define mci map<char,int>
#define fir first
#define sec second
#define eline "\n"

int main() {

	ios::sync_with_stdio(false);
	cin.tie(0);

	double l;
	cin >> l;
	cout.precision(17);
	
	cout << pow(l / 3, 3) << eline;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, K;
  std::cin >> N >> K;
  if(K%2!=0){
    ll ans = 1;
    range(i, 3) ans *= N/K;
    std::cout << ans << '\n';
  }else{
    ll ans = 1;
    ll KK = K/2;
    range(i, 3) ans *= N / KK;
    ll minusone = 3;
    minusone *= N/KK - N/K;
    minusone *= N/KK - N/K;
    minusone *= N/K;
    ll minustwo = 3;
    minustwo *= N/KK - N/K;
    minustwo *= N/K;
    minustwo *= N/K;

    ans = ans - minusone - minustwo;
    std::cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
int main(void){
    int h, w;
    while (1) {
        scanf("%d%d", &h, &w);
        if (h == 0) break;
        for (int i=0; i < h;i++) {
            for (int j=0; j < w; j++) {
                if ((i+j)%2 == 0) printf("#");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll high = 0;
  ll ans = 0;
  
  vector<int> h(n);
  rep(i, 0, n) {
    cin >> h.at(i);
    if(h.at(i) >= high) {
      high = h.at(i);
      ans++;
    }
  }
  
  cout << ans << "\n";

}


Measured memory_bytes: 892
import sys
from collections import Counter
from collections import deque
import math
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
grid=[[0]*10 for i in range(10)]
for i in range(1,n+1):
    a=int(str(i)[0])
    b=int(str(i)[-1])
    grid[a][b]+=1
ans=0
for i in range(10):
    for k in range(10):
        ans+=grid[i][k]*grid[k][i]
print(ans)

Measured memory_bytes: 41708
#include<bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,b,a) for(ll i=b-1;i>=a;i--)
#define hell (int)(1e9+7)
#define int long int

using namespace std;

vector <int> par(100005,-1);

void bfs(int s,int n,int k,string &str){
    priority_queue <int, vector <int> , greater <int> > pq;
    vector <int> dist(n+1,-1);
    pq.push(s);
    dist[s]=0;
    int st=0;
    while(!pq.empty()){
        s=pq.top();
        pq.pop();
        for(int j=st;j<=min(n,s+k);j++){
            if(dist[j]==-1&&str[j]!='1'){
                pq.push(j);
                par[j]=s;
                dist[j]=1+dist[s];
            }
        }
        st=min(n,s+k);
    }
}

void solve(){
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    bfs(0,n,m,s);
    if(par[n]==-1)
        cout<<-1;
    else{
        vector <int> ans;
        int s=n;
        while(s!=-1){
            ans.push_back(s);
            s=par[s];
        }
        reverse(begin(ans),end(ans));
        for(int i=1;i<ans.size();i++)
            cout<<ans[i]-ans[i-1]<<" ";
    }
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3136
s=raw_input().split(' ')
n=int(s[0])
h=int(s[1])

mx=0
ar=[]
for i in range(n):
	s=raw_input().split(' ')
	a=int(s[0])
	b=int(s[1])
	if a>mx:
		mx=a;
	ar.append(b)

v=0
s=0
ar.sort(reverse=True)
for i in range(len(ar)):
	if ar[i]>mx:
		h=h-ar[i]
		v=v+1
	else:
		break;
	if h<=0:
		break;

if h>0:
	if h%mx==0:
		v=v+(h/mx)
	else:
		v=v+(h/mx)+1

print(v)

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

bool acgt(string st){
  bool flag = 1;
  for(char c : st){
    if(c!='A' and c!='C' and c!='G' and c!='T') flag = 0;
  }
  return flag;
}

int main(){
  string s;
  cin >>s;
  string ans="";
  for(int i=0; i<s.size() ;i++){
    for(int j=i; j<s.size(); j++){
      string tmp = s.substr(i,j-i+1);
      if(acgt(tmp)){
        ans = (ans.size()>tmp.size()?ans:tmp);
      }
    }
  }
  cout << ans.size() << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    long long c = 3, m = 1000000007;
    string s, w;
    int n, d, j;
    cin >> n >> s >> w;
    char t = s[0];
    if (n > 1 && s[1] == t) {
        d = 2;
        c = c << 1;
        j = 2;
    }
    else {
        d = 1;
        j = 1;
    }
    for (j; j < n; j++) {
        if (s[j] != w[j]) {
            if (d == 1) {
                c = c << 1;
            }
            else {
                c *= 3;
            }
            d = 2;
            j++;
        }
        else {
            if (d == 1) {
                c = c << 1;
            }
            d = 1;
        }
        c %= m;
    }
    cout << c;
}


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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(1) {
        c = c - b;
        if(c <= 0) {
            cout << "Yes" << endl;
            break;
        }
        a = a - d;
        if(a <= 0) {
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}

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

signed main(){
	int n,q;
	cin >> n >> q;
	string s;
	cin >> s;
	char t[q],d[q];
	rep(i,q){
		cin >> t[i] >> d[i];
	}
	int left = 0, right = n;
	for(int i = q - 1; i >= 0; i--){
		if(t[i] == s[left] && d[i] == 'L') left++;
		if(t[i] == s[right - 1] && d[i] == 'R') right--;
		if(left > 0 && t[i] == s[left - 1] && d[i] == 'R') left--;
		if(right < n && t[i] == s[right] && d[i] == 'L') right++;
	}
	cout << max(0, right - left) << endl;
	return 0;
}

Measured memory_bytes: 900
#include <stdio.h>

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


Measured memory_bytes: 2020
// AOJ Volume 0 Problem 0067

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

int map[14][14];


void init_map(void)
{
	memset(map, 0, sizeof(map));
}

void input_map(void)
{
	char line[20];
	int x, y;
	
	for (y = 1; y <= 12; y++){
		fgets(line, 20, stdin);
		if (strlen(line) < 10){
			exit(0);
		}
		for (x = 1; x <= 12; x++){
			map[y][x] = (line[x - 1] - '0') * -1;
		}
	}
}

int find_island(int island)
{
	int x, y;
	
	for (y = 1; y <= 12; y++){
		for (x = 1; x <= 12; x++){
			if (map[y][x] == -1){
				 map[y][x] = island;
				 return (1);
			}
		}
	}
	return (0);
}

void mark_island(int island)
{
	int flag;
	int x, y;

	flag = 1;
	while (flag == 1){
		flag = 0;	
		for (y = 1; y <= 12; y++){
			for (x = 1; x <= 12; x++){
				if (map[y][x] == -1){
					if (map[y    ][x - 1] == island ||
						map[y - 1][x    ] == island ||
						map[y    ][x + 1] == island ||
						map[y + 1][x    ] == island){
						map[y][x] = island;
						flag = 1;
					}
				}
			}
		}
	}

#if 0
	printf("-------------\n");
	for (y = 1; y <= 12; y++){
		for (x = 1; x <= 12; x++){
			printf("[%2d]", map[y][x]);
		}
		printf("\n");
	}
#endif

}


int main(void)
{
	char dummy[100];
	int island;

	while (1){
		island = 1;
		init_map();
		
		input_map();
		
		while (1){
			if (find_island(island) == 0){
				break;
			}
			mark_island(island);
			island++;
		}
		
		printf("%d\n", island - 1);
		
		if (fgets(dummy, 20, stdin) == NULL){
			break;
		}
	}

	return (0);
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int slen = s.size();

    int cnt = 0;

    for(int i=0;i<(slen/2);i++){
        int j = slen - i - 1;
        // cout << i << " " << j << endl;
        if(s[i] != s[j]) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main(){
	var count int
	var sParam1, sParam2 string
	fmt.Scanf("%d", &count)
	fmt.Scanf("%s %s", &sParam1, &sParam2)

	var i int
	var ret string
	for i = 0; i < count;i++ {
		ret += sParam1[i:i+1]
		ret += sParam2[i:i+1]
	}

	fmt.Printf("%s\n", ret)
}


Measured memory_bytes: 512
fn tax_increase() -> Result<i32, &'static str> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input)
        .map_err(|_| "input error")?;

    let ab: Vec<i32> = input.trim_right()
        .split_whitespace()
        .map(|n| n.parse::<i32>().unwrap())
        .collect();

    let a = ab[0];
    let b = ab[1];
    let mut n: f32 = 1.0;
    loop {
        let an = (n * 0.08) as i32;
        let bn = (n * 0.1) as i32;
        if an == a && bn == b {
            return Ok(n as i32);
        }
        else if an > a && bn > b {
            return Ok(-1);
        }
        n += 1.0;
    }
}

fn main() {
    println!("{}", tax_increase().unwrap());
}

Measured memory_bytes: 4352
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
#pragma endregion

void dfs(string s, int depth, int _max){
  if(depth == N) cout << s << endl;
  else{
    for(int i=0;i<_max +2;i++){
      dfs(s + (char)('a'+i), depth+1, max(_max, i));
    }
  }
}

int main() {
  cin >> N;
  dfs("a", 1, 0);
}



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

#define M 1046527
#define NIL 0
#define L 14



long long getChar(char ch) {
  if (ch == 'A') return 1;
  else if (ch == 'C') return 2;
  else if (ch == 'G') return 3;
  else if (ch == 'T') return 4;
  else return 0;
}

long long getkey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

long long h1(long long key) {
  return key % M;
}

long long h2(long long key) {
  return 1 + (key % (M - 1));
}

long long h(long long key, long long i) {
  return (h1(key) + i * h2(key)) % M;
}

void insert(long long T[], long long key) {
  int i = 0;
  while (1) {
    long long j = h(key, i);
    if (T[j] == NIL) {
      T[j] = key;
      return;
    } else {
      i += 1;
    }
  }
}

int search(long long T[], long long key) {
  int i = 0;
  while (1) {
    long long j = h(key, i);
    if (T[j] == NIL) {
      return 0;
    } else if (T[j] == key) {
      return 1;
    } else {
      i += 1;
    }
  }
}

int main() {
  int i, n;
  long long T[M] = {NIL};
  char str[L], com[9];
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s %s", com, str);
    long long key = getkey(str);
    if (com[0] == 'i') {
      insert(T, key);
    } else {
      int r = search(T, key);
      if (r) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}

Measured memory_bytes: 8772
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

#define ll long long
	
ll A, B, K;

int main()
{
	cin >> A >> B >> K;
	K--;

	if (B - A <= 2 * K) {
		for (int i = A; i <= B; i++)
			cout << i << endl;
	}
	else {
		for (int i = 0; i <= K; i++)
			cout << A + i << endl;
		for (int i = 0; i <= K; i++)
			cout << B - K + i << endl;
	}


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char s[1000];
int main()
{
	scanf("%s",s);
	int len=strlen(s);
	int num=0;
	for(int i=1;i<len-1;i++)
		num++;
	printf("%c%d%c\n",s[0],num,s[len-1]);
	return 0;
}

Measured memory_bytes: 256
////*24-AUG-19*///
//Why do we fall?//
// So we can learn to pick ourself up!//
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define endl "\n"
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr(a,b,c) for(int a=b; a<c; a++)
#define frr(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define pii pair<int,int>
#define R(a) ll a; cin >> a;
#define RA(a, n) ll a[(n) + 1] = {}; fr(i, 1, (n)+1) {cin >> a[i];}
#define RM(a, n, m) int a[n + 1][m + 1] = {}; fr(i, 1, n) {fr(j, 1, m) cin >> a[i][j];}
#define reset(X) memset(X, 0, sizeof(X))
const int inf = 1e18;
const int mod=1e9+7;
unsigned int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool isPrime(int n)
{   if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
    }

    //z function -  z[i] is the length of the longest common prefix between s and the suffix of s starting at i
vector<int>z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}
signed main()
{
    fastio;
    int n,w;
    cin>>n>>w;
    vector<int>dp(w+1,0);
    for(int i=1;i<=n;i++)
    {
        int wa,v;
        cin>>wa>>v;
        for(int j=w-wa;j>=0;j--)
        {
            dp[j+wa]=max(dp[j+wa],dp[j]+v);
        }
    }
    int mx=0;
    fr(i,0,w+1)
    {
        mx=max(dp[i],mx);
    }
    cout<<mx<<endl;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

const int mod = 1000000007;
const int INF = 1001001001;

#define rep(i, n)  for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i, n) cin >> v[i];

    int ans = 0;

    for(int l = 0; l <= min(k, n); l++) {
        for(int r = 0; l + r <= min(k, n); r++) {
            int ansi = 0;
            vector<int> a;
            rep(i, l) {
                ansi += v[i];
                a.push_back(v[i]);
            }
            rep(i, r) {
                ansi += v[n-1-i];
                a.push_back(v[n-1-i]);
            }

            sort(all(a));

            for(int i = 0; i < min(k-(l+r), (int)a.size()); i++) {
                if(a[i] < 0) ansi -= a[i];
            }

            ans = max(ans, ansi);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import static java.lang.Math.atan2;
import static java.lang.Math.sqrt;
import static java.util.Arrays.deepToString;

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		while (sc.hasNext()) {
			int n = sc.nextInt();
			int[][] a = new int[n][n];
			int r = n / 2 + 1;
			int c = n / 2;
			for (int k = 1; k <= n * n; k++) {
				for (;;) {
					if (c >= n) {
						c = 0;
					} else if (c < 0) {
						c = n - 1;
					} else if (r >= n) {
						r = 0;
					} else if (a[r][c] != 0) {
						r++;
						c--;
					} else break;
				}
				a[r][c] = k;
				r++;
				c++;
			}
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					System.out.printf("%4d",a[i][j]);
				}
				System.out.println();
			}
			
		}
	}
	

}

Measured memory_bytes: 20088
import math

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)

def C(n, r):
    return P(n, r)//math.factorial(r)

N = int(input())
arr = {}
ans = 0
for _ in range(N):
    S = input()
    tmp_arr = []
    for i in range(10):
        tmp_arr.append(S[i])
    tmp_arr.sort()
    moji_sorted = ''
    for i in tmp_arr:
        moji_sorted += i
    if moji_sorted in arr:
        arr[moji_sorted] += 1
    else:
        arr[moji_sorted] = 1
# print(arr)

for i in arr.values():
    if i-2 >= 0:
        ans += C(i,2)

print(ans)





Measured memory_bytes: 64088
import java.util.Scanner;

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

		int sheet[][] = new int[3][3];
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				sheet[i][j] = sc.nextInt();
			}
		}

		int N = sc.nextInt();
		for(int n = 0; n < N; n++){
			int x = sc.nextInt();
			for(int i = 0; i < 3; i++) {
				for(int j = 0; j < 3; j++) {
					if(sheet[i][j] == x)sheet[i][j] = 0;
				}
			}
		}

		boolean bingoFlag;

		boolean rowFlag = false;
		boolean columnFlag = false;

		for(int i = 0; i < 3; i++){
			rowFlag = true;
			columnFlag = true;
			for(int j = 0; j < 3; j++){
				if(sheet[i][j] != 0)rowFlag = false;
				if(sheet[j][i] != 0)columnFlag = false;
			}
			if(rowFlag || columnFlag)break;
		}

		bingoFlag = rowFlag || columnFlag;

		boolean rightObliqueFlag = false;
		boolean leftObliqueFlag = false;

		if(!bingoFlag){
			rightObliqueFlag = true;
			leftObliqueFlag = true;
			for(int i = 0; i < 3; i++){
				if(sheet[i][i] != 0)rightObliqueFlag = false;
				if(sheet[i][2 - i] != 0)leftObliqueFlag = false;
			}
			bingoFlag = bingoFlag || rightObliqueFlag || leftObliqueFlag;
		}

		System.out.println((bingoFlag)?"Yes":"No");
	}
}


Measured memory_bytes: 21844
/////////////////////////////////////////
////////// ^\/^ *_* :) :-D '~' \\\\\\\\\\
/////////////////////////////////////////
//#include <bits/stdc++.h>
//#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
//#include <string.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int main()
{
	int n,ans=0,in;
	cin>>n;
	rep(i,n)
	{
		cin>>in;
		ans+=in-1;
	}
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 256
/*  
        D - Knapsack 

        1/12/2019

        https://atcoder.jp/contests/dp/tasks/dp_d
        
        @Ritik Gajjar
*/

#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

typedef long long int ll;

ll dp[2][10000001];

ll maxProfit(pair<int,int> item[] , int totalItem , int cap)
{
    memset(dp , 0 , sizeof(dp));

    for(int i=1 ; i<=totalItem ; i++)
    {
        for(int j=0 ; j<=cap ; j++)
        {
            if(j >= item[i-1].first)
                dp[1][j] = max(item[i-1].second+dp[0][j-item[i-1].first] , dp[0][j]);
            else
                dp[1][j] = dp[0][j];
        }

        for(int j=0 ; j<=cap ; j++)
            dp[0][j] = dp[1][j];
        //cout << "\n";
    }

    return dp[1][cap];
}

int main() 
{
    int totalItem,cap;

    cin >> totalItem >> cap;
    pair<int,int> item[totalItem];
    for(int i=0 ; i<totalItem ; i++)
        cin >> item[i].first >> item[i].second;

    cout << maxProfit(item , totalItem , cap);
    
    return 0;
}


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

int main(){
  int n, d, ans = 0;
  cin >> n >> d;
  long long x, y;
  for(int i=0;i<n;i++){
    cin >> x >> y;
    if(pow(x,2)+pow(y,2)<=pow(d,2))
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3672
h,w = map(int,input().split())

if h%3 == 0 or w%3 == 0:
    print(0)
else:
    #case 1
    h3 = h//3
    w2 = w//2
    c1 = max(h3*w , (h-h3)*w2 , (h-h3)*(w-w2)) - min(h3*w , (h-h3)*w2 , (h-h3)*(w-w2))
    h3 += 1
    c2 = max(h3*w , (h-h3)*w2 , (h-h3)*(w-w2)) - min(h3*w , (h-h3)*w2 , (h-h3)*(w-w2))
    
    #case 2
    w3 = w//3
    h2 = h//2
    d1 = max(w3*h , (w-w3)*h2 , (w-w3)*(h-h2)) - min(w3*h , (w-w3)*h2 , (w-w3)*(h-h2))
    w3 += 1
    d2 = max(w3*h , (w-w3)*h2 , (w-w3)*(h-h2)) - min(w3*h , (w-w3)*h2 , (w-w3)*(h-h2))
    
    print(min(h,w,c1,c2,d1,d2))

Measured memory_bytes: 61720