akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9 + 7, A = 1e5 + 2;
int n, k, p[11], c[11];
ll dp[11][A];
ll solve(int ind, int rem) {
    if (rem <= 0) return 0;
    if (ind == n) return 1e9;
    if (~dp[ind][rem])
        return dp[ind][rem];
    ll val = solve(ind + 1, rem - (p[ind] * (ind + 1)) - c[ind]) + p[ind];
    for (int i = 0; i < p[ind]; i++)
        val = min(val, solve(ind + 1, rem - (i * (ind + 1))) + i);
    return dp[ind][rem] = val;
}
int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> k;
    k /= 100;
    for (int i = 0; i < n; i++) {
        cin >> p[i] >> c[i];
        c[i] /= 100;
    }
    memset(dp, -1, sizeof dp);
    cout << solve(0, k);
    return 0;
}

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

int main(){
  int n; cin >> n;
  vector<int> p(n), q(n);
  for(int i=0; i<n; ++i) cin >> p[i];
  for(int i=0; i<n; ++i) cin >> q[i];
  
  vector<int> per;
  for(int i=0; i<n; ++i) per.push_back(i+1);
  
  int cntp = 1, cntq = 1;
  while(true){
    if(per < p) ++cntp;
    if(per < q) ++cntq;
    if(!(per<p || per<q)) break;
    if(!next_permutation(per.begin(), per.end())) break;
  }
  cout << abs(cntp - cntq) << endl;
  return 0;
}

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

int main(){
	int x,y;
	char s[100];
	int stack[1000000];
	int num=0;

	while (scanf("%s", s) != EOF){
		if (s[0] == '+'){
			x = stack[--num];
			y = stack[--num];
			stack[num] = x + y; 
			num++;
		}
		else if (s[0] == '-'){
			x = stack[--num];
			y = stack[--num];
			stack[num] = -x + y;
			num++;

		}
		else if (s[0] == '*'){
			x = stack[--num];
			y = stack[--num];
			stack[num] = x * y;
			num++;

		}
		else {
			x = atoi(s);
			stack[num] = x;
			num++;
		}
	}
	printf("%d\n",stack[--num]);
	return 0;
}

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



bool winner(vector<ll> v ,ll k){


    bool dp[k+1]={false};

    for(int i=1;i<=k;i++){

        for(int j=0;j<v.size();j++){

            if(i-v[j]<0){
                break;
            }else{

                if(dp[i-v[j]]==false){
                    dp[i]=true;
                    break;

                }

            }
        }

    }

    return dp[k];



}



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

vector<ll > a;
for(ll i=0;i<n;i++){
    ll x;
    cin>>x;
    a.push_back(x);


}

    bool ans=winner(a,k);

    if(ans){
        cout<<"First";

    }else{
        cout<<"Second";
    }





return 0;

}


Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#define rep(i,n) for(lli (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(lli i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const lli MAX=1e5;

int main(){
	lli N,C;
	cin>>N>>C;
	lli x[MAX+1],v[MAX+1];
	lli sv[MAX+1];
	sv[0]=0;
	rep1(i,N){
		cin>>x[i]>>v[i];
		sv[i]=sv[i-1]+v[i];
	}
	lli ans=0;
	lli a[MAX+1],b[MAX+2];
	a[0]=0;
	rep1(i,N)a[i]=max(a[i-1],sv[i]-2*x[i]);
	b[N+1]=0;
	for(lli i=N;i>=1;i--)b[i]=max(sv[N]-sv[i-1]-2*(C-x[i]),b[i+1]);
	
	rep1(i,N){
		ans=max(sv[i]-x[i]+b[i+1],ans);
	}
	rep1(i,N){
		ans=max(sv[N]-sv[i-1]-(C-x[i])+a[i-1],ans);
	}
	cout<<ans;
}

Measured memory_bytes: 4096
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int oddnum = 0;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		if(a % 2 == 1) oddnum++;
	}
	if(oddnum > 0) cout << "first" << endl;
	else cout << "second" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,j,c,d,a,b;
    scanf("%lld %lld",&n,&d);
    double x;
    c=0;
    for(i=0;i<n;i++){
        scanf("%lld%lld",&a,&b);
        j=a*a+b*b;
        x=sqrt(j);
        if(x<=d)
          c++;
    }
    printf("%lld\n",c);
    return 0;
}


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

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか) */

  int n;



  int c;

  while(1){
    cin>>n;

    int cnt[10]={ };

    if(n==0){
      break;
    }

    for(int i=0;i<n;i++){
      cin>>c;

      cnt[c]+=1;
    }

    for(int i=0;i<10;i++){
      if(cnt[i]==0){
	cout<<'-';
      }else{
	for(int j=0;j<cnt[i];j++){
	  cout<<'*';
	}
      }
      cout<<endl;
    }
  }      
  return 0;

}



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

#define co(x) cout << x << endl ;

int main ()
{
    string s , c ;
    int cou = 0 ;

    cin >> s ;
    cin >> c ;

    for (int i = 0 ; i < 3 ; i ++)
    {
        if (s[i] == c[i])
        {
            cou ++ ;
        }
    }

    co (cou)

    return 0 ;
}

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

typedef long long int ll;


int main()
{
    ll  q;
    cin >> q;
    vector<pair<ll, ll>> lr(q);
    ll mr = 0;
    for(ll i = 0;i < q;i++){
        cin >> lr[i].first >> lr[i].second;
        mr = max(mr, lr[i].second);
    } 
    vector<ll> s(mr + 1);
    s[1] = -1;
    for(ll i = 1;i * i <= mr;i++){
        if(s[i] != -1){
            for(ll j = i + i;j <= mr;j += i){
                s[j] = -1;
            }
        }
    }

    vector<ll> b(mr + 1);

    for(ll i = 1;i <= mr;i++){
        if(s[i] != -1){
            if(s[(i + 1) / 2] != -1){
                b[i] = -1;
            }
        }
    }

    vector<ll> r(mr + 1);
    for(ll i = 1;i <= mr;i++){
        r[i] = r[i - 1];
        if(b[i] == -1){
            r[i]++;
        }
    }

    for(ll i = 0;i < q;i++){
        cout << r[lr[i].second] - r[lr[i].first - 1] << "\n";
    }


    return 0;
}

Measured memory_bytes: 4608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		int date[] = {0,31,29,31,30,31,30,31,31,30,31,30,31};

		while(!(str=br.readLine()).equals("0 0")){
			String strArray[] = str.split(" ");
			int month = Integer.parseInt(strArray[0]);
			int day = Integer.parseInt(strArray[1]);

			for(int i=0; i<month; i++){
				day += date[i];
			}

			switch (day%7) {
			case 1:
				System.out.println("Thursday");
				break;
			case 2:
				System.out.println("Friday");
				break;
			case 3:
				System.out.println("Saturday");
				break;
			case 4:
				System.out.println("Sunday");
				break;
			case 5:
				System.out.println("Monday");
				break;
			case 6:
				System.out.println("Tuesday");
				break;
			default:
				System.out.println("Wednesday");
				break;
			}
		}
	}
}

Measured memory_bytes: 16924
#include <stdio.h>
#include <stdlib.h>

typedef struct _node{
	struct _node *prev;
	struct _node *next;

	int val;

}Node;


void insert(Node **head, Node **tail,  int val ){

	Node *ptr;


	ptr = (Node*)malloc(sizeof(Node));
	ptr->val = val;

	ptr->prev = NULL;
	ptr->next = *head;

	if( *head != NULL ) {
		(*head)->prev = ptr;
		*head = ptr;
	}else{
		*head = ptr;
		*tail = ptr;
	}
	
}

void delete_first( Node **head, Node **tail ){
	
	Node *ptr = *head;

	if( ptr->next != NULL ){
		ptr->next->prev = NULL;
		*head = ptr->next;
	}else{
		*head = NULL;
		*tail = NULL;
	}

	free(ptr);
}


void delete_last( Node **head, Node **tail ){

	Node *ptr = *tail;

	if( ptr->prev != NULL ){
		ptr->prev->next = NULL;
		*tail = ptr->prev;
	}else{
		*head = NULL;	
		*tail = NULL;
	}
	free( ptr );
}

void delete(Node **head, Node **tail, int val ){

	Node *ptr = *head;
	if(*head == NULL) return;

	//Seek for matching node
	while( ptr->next!=NULL && ptr->val!=val  )
		ptr = ptr->next;

	// delete
	if( ptr->val == val ){

		if( ptr->next == NULL ){
			delete_last(head, tail);
		}else if( ptr->prev == NULL ){
			delete_first(head, tail);
		}else{
			ptr->prev->next = ptr->next;
			ptr->next->prev = ptr->prev;
			free(ptr);
		}
	}
}





void print( Node * node ){

		
	if(node==NULL) return;
	
	do{
		printf( "%d%c", node->val, (node->next!=NULL)?' ':'\n' );
		node  = node->next;
	}while( node != NULL  );
}

int main( ){

	int i, n, val;
	char cmd[33];
	Node *head=NULL, *tail=NULL;
	

	scanf( "%d\n", &n );
	
	for( i=0; i<n; i++ ){
		fgets( cmd, sizeof(cmd), stdin );

		if( cmd[0]=='d' && cmd[6]=='F' ){
			delete_first( &head, &tail );
		}
		else if( cmd[0]=='d' && cmd[6]=='L' ){
			delete_last( &head, &tail );
		}
		else if( cmd[0] == 'd' ){
			val = atoi( &cmd[7] );
			delete( &head, &tail, val );
		}
		if( cmd[0]=='i' ){
			val = atoi( &cmd[7] );
			insert( &head, &tail, val );
		}
	}

	print(head);
	
	return 0;
}

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

#pragma GCC optimize("O3")

using namespace std;

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

typedef long long ll;

void solve(){
	int k, n;
	cin >> k >> n;
	vector<int> dis(n);
	for(int i = 0; i < n; ++i) cin >> dis[i];
	int bigger = 0;
	int sum = 0;
	for(int i = 0; i < n; ++i) {
		int value;
		if(i < n - 1) {
			value = dis[i+1] - dis[i];
			sum += value;
		} else {
			value = k - dis[i] + dis[0];
			sum += value;
		}
		
		if(value > bigger) bigger = value;
	}
	cout << sum-bigger;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    solve();
    
    return 0;
}


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

int main() {
  string s;
  int cnt = 0;
  cin >> s;
  rep(i,1,s.size()) if(s[i] != s[i-1]) cnt++;
  cout << cnt << endl;
}

Measured memory_bytes: 3776
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

mod=10**9+7

A.sort(reverse=True)
B.sort(reverse=True)

nind=0
mind=0
#nused=0
#mused=0
used=0
ANS=1
for innum in range(N*M,0,-1):
    if nind<N and mind<M and A[nind]==B[mind]==innum:
        nind+=1
        mind+=1
        #nused=1
        #mused=1
        used+=1

    elif nind<N and A[nind]==innum and (mind==M or B[mind]<innum ):
        ANS=ANS*(mind)%mod
        nind+=1
        used+=1

    elif mind<M and B[mind]==innum and (nind==N or A[nind]<innum):
        ANS=ANS*(nind)%mod
        mind+=1
        used+=1

    elif (nind==N or A[nind]<innum) and (mind==M or B[mind]<innum):
        ANS=ANS*(nind*mind-used)%mod
        used+=1
    else:
        ANS=0

    #print(innum,ANS)

print(ANS)
        
        
        
        
    
    


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

#define pb push_back
#define mp make_pair
#define ll long long int
#define all(x) x.begin(), x.end()

unordered_set<int> seen;

map<pair<int, int>, int> done;
vector<pair<int, int>> ip;
void solve() {
    int nodes;
    cin >> nodes;
    vector<vector<int>> graph(nodes);
    for(int i = 0; i < nodes-1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);

        ip.pb(mp(min(a, b), max(a, b)));
        // done[] = -1;
    }

    int ans = 0;

    queue<pair<int, int>> q;
    q.push(mp(0, -1));

    while(!q.empty()) {        
        pair<int, int> pp = q.front();
        q.pop();

        auto node = pp.first;
        auto color = pp.second;
        // cout << "node: " << node << " color: " << color << "\n";
        int fc = 1;
        
        if(seen.find(node) != seen.end()) continue;
        seen.insert(node);

        for(auto child: graph[node]) {
            if(seen.find(child) != seen.end()) continue;
            if(fc == color) fc++;
            // cout << "node: " << node << " adding child: " << child << " and color: " << color << "\n";  
            q.push(mp(child, fc));
            done[mp(min(child, node), max(child, node))] = fc;
            if(ans < fc) {
                ans = fc;
            }

            fc++;
        }
    }

    cout << ans << "\n";
    for(auto p: ip) {
        cout << done[p] << "\n";
    }
    
}

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

    solve();
    return 0;
}

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

int next(int a) {
  if (a % 2 == 0) {
    return a/2;
  }
  else {
    return 3*a + 1;
  }
}

int main() {
  int s;
  cin >> s;
  set<int> table;
  int count = 1;
  
  while(1) {
    if (table.count(s)) {
      break;
    }
    else {
      table.insert(s);
      s = next(s);
      count++;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10**9 + 7

N = int(readline())
X = np.array(read().split(),np.int64)

# いくつ居なくなったらゴールできるか
x = (2*np.arange(N) + 2 - X)//2
x = np.maximum(x,0)
np.maximum.accumulate(x,out=x)

x = np.bincount(x[:-1],minlength=N)
x[0] += 1
np.cumsum(x,out=x)
x -= np.arange(len(x))

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

answer = cumprod(x,MOD)[-1]
print(answer)



Measured memory_bytes: 18572
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[100001],h[100001];
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for(register int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]<h[i-1]-1){
			puts("No");
			return 0;
		}
		h[i]=max(h[i-1],a[i]);
	}
	puts("Yes");
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
	int main(){
		int n,A,B,x,y,xy,i;
		char a[20],b[20];
		scanf("%d",&n);
		while(n-->0){
			x=0;
			y=0;
			scanf("%s %s",a,b);
			A=strlen(a);
			for(i=0;i<A;i++)
				if(a[i]=='m'||a[i]=='c'||a[i]=='x'||a[i]=='i'){
					if(i!=0){
						if(a[i-1]!='m'&&a[i-1]!='c'&&a[i-1]!='x'&&a[i-1]!='i'){
							if(a[i]=='m')
								x+=(a[i-1]-'0')*1000;
							else if(a[i]=='c')
								x+=(a[i-1]-'0')*100;
							else if(a[i]=='x')
								x+=(a[i-1]-'0')*10;
							else
								x+=a[i-1]-'0';
						}
						else {
							if(a[i]=='m')
								x+=1000;
							else if(a[i]=='c')
								x+=100;
							else if(a[i]=='x')
								x+=10;
							else
								x+=1;
						}
					}
					else {
						if(a[i]=='m')
								x+=1000;
							else if(a[i]=='c')
								x+=100;
							else if(a[i]=='x')
								x+=10;
							else
								x+=1;
					}
			}
			B=strlen(b);
			for(i=0;i<B;i++)
				if(b[i]=='m'||b[i]=='c'||b[i]=='x'||b[i]=='i'){
					if(i!=0){
						if(b[i-1]!='m'&&b[i-1]!='c'&&b[i-1]!='x'&&b[i-1]!='i'){
							if(b[i]=='m')
								y+=(b[i-1]-'0')*1000;
							else if(b[i]=='c')
								y+=(b[i-1]-'0')*100;
							else if(b[i]=='x')
								y+=(b[i-1]-'0')*10;
							else
								y+=b[i-1]-'0';
						}
						else {
							if(b[i]=='m')
								y+=1000;
							else if(b[i]=='c')
								y+=100;
							else if(b[i]=='x')
								y+=10;
							else
								y+=1;
						}
					}
					else {
						if(b[i]=='m')
								y+=1000;
							else if(b[i]=='c')
								y+=100;
							else if(b[i]=='x')
								y+=10;
							else
								y+=1;
					}
			}
			xy=x+y;
			if(xy/1000>1)
				printf("%d",xy/1000);
			if(xy/1000!=0)
			printf("m");
			xy-=(xy/1000)*1000;
			
			
			if(xy/100>1)
				printf("%d",xy/100);
			if(xy/100!=0)
			printf("c");
			xy-=(xy/100)*100;
			
			if(xy/10>1)
				printf("%d",xy/10);
				if(xy/10!=0)
			printf("x");
			xy-=(xy/10)*10;
			
			if(xy>1)
				printf("%d",xy);
			if(xy!=0)
			printf("i");
			printf("\n");
		}
		return 0;
}

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

#define int long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).end()
#define pb push_back
#define pf push_front
#define fori(i, a, n) for(int i = a; i < n; ++i)
#define MAX(x) (*max_element(all(x)))
#define MIN(x) (*min_element(all(x)))
#define sortarr(a,n) sort(a, a+n)
#define sortvec(V) sort(all(V))

typedef vector<int> V;
typedef pair<int , int> pairi;
typedef set<int> seti;
typedef deque<int> deqi;

const int MOD = 1e9+7;
const int INF = 1e9+8;
const double pi = 3.14159265359;

template <class T>
T fac(T n)      // template function to find factorial of a number
{ 
    T res = 1, i; 
    for (i = 2; i <= n; i++) 
        res *= i; 
    return res; 
}
template<class T>
T lcm(T a, T b)     //template function to find lcm of two numbers 
{
    return (a * b) / __gcd(a,b);
}
template<class T>
T digitsum(T x)
{
    T sum = 0;
    while(x)
    {
        sum += x%10;
        x /= 10;
    }
    return sum;
}
// ternary search
/*double ternary(double l, double r){
    double eps = 1e-9;
    while(r - l > eps){
        double m1 = l + (r - l)/3;
        double m2 = r - (r - l)/3;
        double f1 = f(m1);
        double f2 = f(m2);
        if(f1 < f2)
            l = m1;
        else r = m2;
    }
    return f(l);
}*/
void nPermute(string str, int n)  //function to find nth  lexi string
{ 
    sort(all(str));
    int i = 1; 
    do {
        if (i == n) 
            break; 
  
        i++; 
    } while (next_permutation(str.begin(), str.end())); 
    cout<<str<<endl;
} 
vector<int> factors(int n) 
{ 
    vector<int> f; 
    for(int x = 2; x * x <= n; x++) { 
        while (n % x == 0) { 
            f.push_back(x); 
            n /= x; 
        } 
    } 
    if (n > 1) f.push_back(n); 
    return f; 
}
bool prime(int n) 
{ 
    if (n < 2)
        return false;
    for(int x = 2; x*x <= n; x++) 
        if (n%x == 0) 
            return false; 
    return true; 
}
// binomial coeficient in O(K) 
int ncr(int n, int k){
    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;
}
tuple<int, int, int> Gcd(int a, int b)      //extended Euclids Algorithm
{
    if(b == 0)
        return {1, 0, a};
    else{
        int x, y, g;
        tie(x, y, g) = Gcd(b, a%b);
        return {y, x - (a/b)*y, g};
    }
}
template<class T>       // modular Exponentiation x^n mod m = x^(n mod (m - 1)) mod m : if n  is very large;
T binpow(T a, T b, T m) {
    a %= m;
    T res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
void solve()
{
    int n, k;
    cin >> n >> k;
    V a(n);
    for(auto & i : a)   cin >> i;
    sortvec(a);
    int sum = 0;
    for(int i = 0; i < k; i++)
        sum += a[i];
    cout << sum << endl;
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}

Measured memory_bytes: 3848
s = input()

n = len(s) + 1
a = [0] * n
for i in range(n - 1):
    if s[i] == '<':
        a[i + 1] = a[i] + 1

for i in range(n - 2, - 1, -1):
    if s[i] == '>':
        if a[i] <= a[i + 1] + 1:
            a[i] = a[i + 1] + 1

print(sum(a))


Measured memory_bytes: 23336
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
     sc.Split(bufio.ScanWords)
     var a [3][3]int

     for i:=0; i<3; i++ {
     	 for j:=0; j <3; j++ {
	     a[i][j] = nextInt()
	 }
     }

     n := nextInt()
     b := make([]int, n)

     for i:=0; i<n; i++{
     	 b[i] = nextInt()
     }

     for i:=0; i<3; i++ {
     	 for j:=0; j<3; j++ {
	     for k:=0; k<n; k++ {
	     	 if a[i][j] == b[k] {
		    a[i][j] = 0
		 }
	     }
	 }
     }

     buf := make([]int, 8)
     for i:=0; i<3; i++ {
     	 buf[i] = a[i][0] + a[i][1] + a[i][2]
	 buf[i+3] = a[0][i] + a[1][i] + a[2][i]
     }
     buf[6] = a[0][0] + a[1][1] + a[2][2]
     buf[7] = a[2][0] + a[1][1] + a[0][2]

     ans := "No"

     for i:=0; i<8; i++ {
     	 if buf[i] == 0 {
	    ans = "Yes"
	 }
     }

     fmt.Println(ans)
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
	int H, W, K;
	cin >> H >> W >> K;
	vector<string> S(H);
	for (auto& x : S) cin >> x;
	vector<vector<int>> a(H, vector<int>(W));
	int cnt = 0;
	for (int i = 0; i < H; ++ i) {
		for (int j = 0; j < W; ++ j) {
			if (S[i][j] == '#') a[i][j] = ++ cnt;
			else if (j > 0) a[i][j] = a[i][j-1];
		}
		for (int j = W-2; j >= 0; -- j) {
			if (a[i][j] == 0) a[i][j] = a[i][j+1];
		}
	}
	for (int i = 1; i < H; ++ i) {
		for (int j = 0; j < W; ++ j) {
			if (a[i][j] == 0) a[i][j] = a[i-1][j];
		}
	}
	for (int i = H-2; i >= 0; -- i) {
		for (int j = 0; j < W; ++ j) {
			if (a[i][j] == 0) a[i][j] = a[i+1][j];
		}
	}
	for (int i = 0; i < H; ++ i) {
		for (int j = 0; j < W; ++ j) {
			if (j) cout << " ";
			cout << a[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 1280
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
    int n;
    int cnt = 0;
    while (cin >> n)
    {
        cnt = 0;
    for (int a = 0 ; a <= 9 ; a++)
    {
        for (int b = 0 ; b <= 9 ; b++)
        {
            for (int c = 0 ; c <= 9 ; c++)
            {
                for (int d = 0 ; d <= 9 ; d++)
                {
                    if (a+b+c+d == n)
                        cnt ++;
                }
            }
        }
    }
    cout << cnt << endl;
    }
}

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

int main(){
	int a,b,c,x;
	cin >> a >> b >> c;
	if(a>b){
		x=a;
		a=b;
		b=x;
	}
	if(b>c){
		x=b;
		b=c;
		c=x;
	}
	if(a>b){
		x=a;
		a=b;
		b=x;
	}
	cout << a << " "<< b << " " << c << endl;
	return 0;
}


Measured memory_bytes: 3112
import math

def plot(x, y):
    print(f'{x:.8f} {y:.8f}')

def Koch(n, x1, y1, x2, y2):
    if n == 0:
        plot(x1, y1)
        return
    sx = (2*x1 + x2) / 3
    sy = (2*y1 + y2) / 3
    tx = (x1 + 2*x2) / 3
    ty = (y1 + 2*y2) / 3
    ux = (tx - sx) * (1/2) - (ty - sy) * (math.sqrt(3))/2 + sx
    uy = (tx - sx) * (math.sqrt(3))/2 + (ty - sy) * (1/2) + sy
    Koch(n-1, x1, y1, sx, sy)
    Koch(n-1, sx, sy, ux, uy)
    Koch(n-1, ux, uy, tx, ty)
    Koch(n-1, tx, ty, x2, y2)


n = int(input())
Koch(n, 0, 0, 100, 0)
    
plot(100, 0)


Measured memory_bytes: 5756
#include <bits/stdc++.h>
using namespace std;
//#define P pair<int,int>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)

// n個の中からk個選ぶ 0~n-1 bitで表現 n<=18 k<=n
vector<int> combination(int n,int k){
	vector<int> ans;
	int x = (1<<k)-1;
	int f = x<<(n-k);
	while(1){
		ans.push_back(x);
		if(x==f)return ans;
		x += x&-x;
		int pcount = bitset<64>(x).count();
		x|=(1<<(k-pcount))-1;
	}
}

struct Inversions{// tentosu
	// after init,u can get number of inversions num_inversion(A)
	vector<int> L,R;
	void initsize(int n){//input size of A
		L.resize(n/2+2);
		R.resize(n/2+2);
	}
	int merge(vector<int> &A,int n,int left,int mid,int right){
		int i,j,k;
		int cnt = 0;
		int n1 = mid - left;
		int n2 = right - mid;
		for(i=0;i<n1;i++)L[i]=A[left+i];
		for(i=0;i<n2;i++)R[i]=A[mid+i];
		L[n1]=R[n2]=INT_MAX;//
		i=j=0;
		for(k=left;k<right;k++){
			if(L[i]<=R[j]){
				A[k]=L[i++];
			}else{
				A[k]=R[j++];
				cnt += n1-i;
			}
		}
		return cnt;
	}
	int mergeSort(vector<int> &A,int n,int left,int right){
		int mid;
		int v1,v2,v3;
		if(left+1<right){
			mid = (left+right)/2;
			v1 = mergeSort(A,n,left,mid);
			v2 = mergeSort(A,n,mid,right);
			v3 = merge(A,n,left,mid,right);
			return v1+v2+v3;
		}else return 0;
	}
	int num_inversion(vector<int> A){
		vector<int> B=A;//Aの順番を変えたくないなら
		return mergeSort(B,B.size(),0,B.size());
	}
};


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N,n,ans=-1;
	cin >> N;
	n = N/2;
	if(N==1){
		cout << 0 << endl;
		return 0;
	}
	vector<int> A(N),B(N);
	for(int i=0;i<N;i++) cin >> A[i];
	for(int i=0;i<N;i++) cin >> B[i];
	for(int ch=0; ch<=n; ch++){
		auto chodd = combination( n,ch );
		auto cheve = combination( N-n,ch );
		for(auto odds : chodd){
			for(auto eves : cheve){
				vector<pair<int,int>> odd,eve;
				for(int i=0;i<n;i++){
					if(odds&(1<<i)){
						eve.push_back({B[2*i+1],2*i+1});
					}else{
						odd.push_back({A[2*i+1],2*i+1});
					}
				}
				for(int i=0;i<N-n;i++){
					if(eves&(1<<i)){
						odd.push_back({B[2*i],2*i});
					}else{
						eve.push_back({A[2*i],2*i});
					}
				}
				sort(odd.begin(), odd.end());
				sort(eve.begin(), eve.end());
				vector<int> to_ind,value;
				for(int i=0;i<n;i++){
					value.push_back(eve[i].first);
					to_ind.push_back(eve[i].second);
					value.push_back(odd[i].first);
					to_ind.push_back(odd[i].second);
				}
				if(N&1){
					value.push_back(eve[n].first);
					to_ind.push_back(eve[n].second);
				}
				bool none = false;
				for(int i=0;i<N-1;i++) if(value[i]>value[i+1]) none = true;
				if(none) continue;
				Inversions inv;
				inv.initsize(N);
				int cnt = inv.num_inversion(to_ind);
				if(ans==-1) ans = cnt;
				ans = min(ans,cnt);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
//AZ@RK2019
//I know it wll accepted in first go! 
#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
const int N = 2e5+7;
int n,m,u,v;
bool f[N],e[N];
int main(){
	cin >> n >> m;
	for(int i = 1;i <= m;i++){
		cin >> u >> v;
		if(u == 1 or v == 1){
			f[v] = true;
			f[u] = true;
		}
		if(u == n or v == n){
			e[u] = true;
			e[v] = true;
		}
	}
	for(int i = 1;i <= n;i++){
		if (f[i] and e[i]){
			cout << "POSSIBLE";
			return 0;
		}
	}
	cout << "IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 640
def main():
    n = int(input())
    a = list(map(int, input().split()))
    l1 = [0]*61
    for i in a:
        cnt = 0
        k = 1
        while k <= i:
            if i & k == k:
                l1[cnt] += 1
            cnt += 1
            k *= 2
    l0 = [n-i for i in l1]
    ans = 0
    mod = 10**9+7
    for i in range(len(l1)):
        ans = (ans+l0[i]*l1[i]*pow(2, i, mod)) % mod
    print(ans)
main()

Measured memory_bytes: 122808
/*input
FFFFFFF
7 0
*/
#include<bits/stdc++.h>
using namespace std;
const int N=8001;
const int mod=1e9 + 7;
#define int long long
const int inf=1e18;
#define pii pair<int, int>
#define f first
#define s second 
#define mp make_pair
set<int> dp[4001];string st;int t[2];
vector<int> arr[2];
bool solve(int ind, int start)
{
	int sum=0;
	for(auto j:arr[ind]) sum+=j;
	for(int i=0;i<4001;i++) dp[i].clear();
	dp[0].insert(start);
	for(int i=0;i<arr[ind].size();i++)
	{
		sum-=arr[ind][i];//cout<<i<<" : ";
		for(auto j:dp[i])
		{
//			cout<<j<<" ";
			if((t[ind]>0&&j + arr[ind][i] - sum <=t[ind])||(t[ind]<=0&&j + arr[ind][i] + sum >=t[ind])) dp[i+1].insert(j+arr[ind][i]);
			if((t[ind]>0&&j - arr[ind][i] - sum <=t[ind])||(t[ind]<=0&&j - arr[ind][i] + sum >=t[ind])) dp[i+1].insert(j-arr[ind][i]);
		}
	}
	return dp[arr[ind].size()].count(t[ind]);
}
signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>st>>t[0]>>t[1];int cur=0, ind=0;
	for(auto i:st)
	{
		if(i=='F') cur++;
		else
		{
			arr[ind].push_back(cur);cur=0;ind^=1;
		}
	}
	if(cur!=0) arr[ind].push_back(cur);
	int val=arr[0][0];arr[0].erase(arr[0].begin());
	if(solve(0, val)&&solve(1, 0)) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 178304
N,M=map(int,input().split())
Z=[1]*(N+1)
Z[0]=0

H=[False]*(N+1)
H[1]=True

for _ in range(M):
    X,Y=map(int,input().split())

    H[Y]|=H[X]

    Z[X]-=1
    Z[Y]+=1

    H[X]&=(Z[X]!=0)
print(sum(H))


Measured memory_bytes: 76236
#include <stdio.h>
#include <math.h>

int main(void)
{
	int n, x[100], y[100], count, sum[100], D_inf;
	double D1, D2, D3, sum_2;

	scanf("%d", &n);

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

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

	for (D1 = 0, count = 0; count < n; count++)
	{
		D1 = D1 + (double)fabs(x[count] - y[count]);
	}

	for (D2 = 0, count = 0; count < n; count++)
	{
		D2 = D2 + (double)pow(fabs(x[count] - y[count]), 2);
	}
	
	D2 = sqrt(D2);

	for (D3 = 0, count = 0; count < n; count++)
	{
		D3 = D3 + (double)pow(fabs(x[count] - y[count]), 3);
	}
	
	D3 = pow(D3, (0.333333333333333));

	for (count = 0, sum[count] = 0; count < n; count++)
	{
		sum[count] = fabs(x[count] - y[count]);
	}

	for (count = 0, D_inf = sum[count]; count < (n - 1); count++)
	{
		if (D_inf < sum[count + 1])
		{
			D_inf = sum[count + 1];
		}
	}

	printf("%0.8f %0.8f %0.8f %0.8f\n", D1, D2, D3, (double)D_inf);
	return 0;
}


Measured memory_bytes: 2100
#71d
N = int(input())
Sone = list(input())
Stwo = list(input())

mod_by = 7 + 10**9

#最初のだけ別計算
if Sone[0]==Stwo[0]:
    #ドミノは縦置き
    ans = 3
    before_domino = 1
    i = 1
else:
    #ドミノは横置き
    ans = 6 # 3色*3色-3通り(上下同色)
    before_domino = 0
    i = 2

#前のドミノが縦置き(before_domino=1)の場合
#→今のドミノが縦置きなら2通り
#→今のドミノが横置きなら2通り

#前のドミノが横置き(before_domino=0)の場合
#→今のドミノが縦置きなら1通り
#→今のドミノが横置きなら3通り
    
while i < N:
    if Sone[i] == Stwo[i] and before_domino == 1:
        ans *= 2
        before_domino = 1
        i += 1
    elif Sone[i] != Stwo[i] and before_domino == 1:
        ans *= 2
        before_domino = 0
        i += 2
    elif Sone[i] == Stwo[i] and before_domino == 0:
        ans *= 1
        before_domino = 1
        i += 1
    elif Sone[i] != Stwo[i] and before_domino == 0:
        ans *= 3
        before_domino = 0
        i += 2
        
print(ans%mod_by)

Measured memory_bytes: 3064
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 
ll n, k;
vll a;
bool can(ll x) {
  vll aux;
  ll tt = 0;
  for(ll i = 0; i < n; i++) {
    tt+= a[i]%x;
    aux.pb(a[i]%x);
  }
  vll sec;
  sort(all(aux));
  for(auto it : aux) {
    sec.pb(x - it);
  }
  for(ll i = 1; i < n; i++) aux[i]+= aux[i-1];
  for(ll i = n-2; i >= 0; i--) sec[i]+= sec[i+1];
  if(sec[0] == 0 or aux[n-1] == 0) return true;
  for(ll i = 0; i < n-1; i++) {
    if(aux[i] == sec[i+1]) {
      if(aux[i] <= k) return true;
    }
  }
  return false;
}
vll factors(ll x) {
  vll ans;
  for(ll i = 1; i*i <= x; i++) {
    if(x%i == 0) {
      if(x/i == i) {
        ans.pb(i);
      } else {
        ans.pb(x/i);
        ans.pb(i);
      }
    }
  }
  return ans;
}

int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  cin >> n >> k;
  a.resize(n);
  for(ll i = 0; i < n; i++) cin >> a[i];
  ll s = 0;
  for(ll i = 0; i < n; i++) {
    s+= a[i];
  }
  ll ans = 1;
  vll facts = factors(s);
  for(auto it: facts) {
    if(can(it)) ans = max(ans, it);
  }
  cout << ans << endl;
  return 0;
} //good night.

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

struct Node{
	ll ch[2];
	int cost;
	int h;

	Node(){
		memset(ch, -1, sizeof ch);
		cost = 0;
	}
};

vector<Node> trie;

void add_str(int v, string& s, int i, int cost){
	if(s.size() == i){
		trie[v].cost = cost;
		return;
	}

	trie[v].h = i;

	if(trie[v].ch[s[i]-'0'] == -1){
		trie.push_back(Node());
		trie[v].ch[s[i]-'0'] = trie.size()-1;
	}

	add_str(trie[v].ch[s[i]-'0'], s, i+1, cost);
}

ll modpow(ll a, ll b){
	if(b < 0) return 0;
	if(b == 0) return 1;
	if(b % 2) return (a*modpow(a,b-1))%3;
	ll ret = modpow(a, b/2);
	return ret*ret%3;
}

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

	ll N, L;
	ll res = 0;
	cin >> N >> L;
	trie.push_back(Node());
	REP(i, N){
		string s;
		cin >> s;
		add_str(0, s, 0, 0);
	}
  auto grundy=[](ll x){
    ll k=1;
    while(x%2==0) x>>=1,k<<=1;
    return k;
  };
	REP(i, trie.size()){
		if(trie[i].ch[0] * trie[i].ch[1] < 0){
			res ^= grundy(L-trie[i].h);
		}
	}
	if(res == 0){
		cout << "Bob" << endl;
	}else{
		cout << "Alice" << endl;
	}
}


Measured memory_bytes: 13760
using System;
using System.Collections.Generic;
using System.Text;

class Program {

    public void Proc() {
        string[] inpt = Console.ReadLine().Split(' ');
		int n = int.Parse(inpt[0]);
		int k = int.Parse(inpt[1]);
		double ans = k * System.Math.Pow(k-1, n-1);
        Console.WriteLine(ans);
    }

    static void Main(string[] args) {
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 2648
#include <stdio.h>

void dP(int* A, int N){
  int n;
  for (n=0;n<(N-1);n++)
    printf("%d ",A[n]);
  printf("%d\n",A[N-1]);
}

void s(int* A, int N){
  int i;
  for (i=1;i<N;i++) {
    int k=A[i];
    int j=i-1;
    dP(A,N);
    while((j>=0)&&(A[j]>k)) {
      A[j+1]=A[j];
      j--;
      A[j+1]=k;
    }
  }
}

int main(void) {
  int I[100],N,n;
  scanf("%d\n",&N);
  for(n=0;n<N;n++)
    scanf("%d",&I[n]);
  s(I,N);
  dP(I,N);
  return 0;
}

Measured memory_bytes: 600
/////////////////////////////////
//                             //
//           /(.^.)\           //
//                             //
/////////////////////////////////

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

#define BYTE unsigned char
#define DWORD unsigned int
#define QWORD unsigned long long
#define LL long long


//デバッグプリント
void xxxcoutxxx(int a, int f = 0)
{
    cout << a << " "; if (f) cout << endl;
    return;
}


//main
int main()
{
    int rtn = 0;
    
    vector<int> ccc;

    ccc.push_back(1);

    int n,a;
    int f;
    
    int st;

    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        cin >> a;

        f = 1;

        st = distance(ccc.begin(),upper_bound(ccc.begin(),ccc.end(),-a));
        
        if (st >= ccc.size())
        {
            ccc.push_back(-a);
        }
        else
        {
            for (int ii = st; ii < ccc.size(); ++ii)
            {
                if (ccc[ii] > -a)
                {
                    ccc[ii] = -a;
                    f = 0;
                    break;
                }
            }

            if (f)
            {
                ccc.push_back(-a);
            }
        }

    }

    rtn = ccc.size();
    cout << rtn;
    return 0;
    cout << "/(.^.)\\" << endl;
}

Measured memory_bytes: 892
#agc17-b
n,a,b,c,d=map(int,input().split())
ans='NO'
maxi=a+d*(n-1)
mini=a+c*(n-1)
if mini<=b<=maxi:
    ans='YES'

else:
    for i in range(1,n):
        maxi=maxi-d-c
        mini=mini-c-d
        if mini<=b<=maxi:
            ans='YES'
            break

print(ans)

Measured memory_bytes: 9120
#include<stdio.h>
#include<math.h>

typedef long long ll;

int main(void){
    ll a, b, c;
    scanf("%ld %ld %ld", &a, &b, &c);
    if(0<c-a-b && (c-a-b)*(c-a-b)>4*a*b){
        puts("Yes");
    }else{
        puts("No");
    }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n,a,b;cin>>n>>a>>b;
	string s;cin>>s;
	int cnta = 0;
	int cntb = 0;
	for(int i = 0; i < s.size(); i++) {
		if (s[i] =='a'){
			if (cnta + cntb < a + b){
				cout << "Yes" << endl;
				cnta++;
			}
			else{
				cout << "No" << endl;
			}
		}
		else if (s[i] == 'b'){
			if (cnta + cntb < a + b && cntb < b){
				cout << "Yes" << endl;
				cntb++;
			}
			else{
				cout << "No" << endl;
			}
		}
		else{
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 896
#include<iostream>

using namespace std;
int main()
{
  int n,ans=0,weishu=0,tmp,counter=1;
  cin>>n;
  tmp = n;
  while(tmp>0)
  {
    weishu++;
    tmp/=10;
  }
 for(int i = 1;i<=weishu;i++)
 {
   if(i%2==1)
   {
     if(i==weishu)
    	ans+=(n-counter+1);
     else
       ans+=(9*counter);
   }
   counter*=10;
 }
  cout<<ans<<endl;
 return 0; 
}

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

#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define exp2(x)  (1LL<<(x))

using namespace std;
using ll=long long;


int main() {
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
  int n; cin >> n;
  vector<int> p(n); rep(i, 0,n-1) cin >> p[i];
  int c = 0;
  rep(i, 1,n-2) {
      vector<int> k = {p[i-1], p[i], p[i+1]};
      sort(k.begin(), k.end());
      if (k[1] == p[i]) c++;
  }

  END(c);

}


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

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


int main()
{
    int N, T;
    cin >> N >> T;
    vector<pair<int,int>> dish(N);
    REP(i, N) cin >> dish[i].first >> dish[i].second;

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

    // dp[i][j] = i 番目を時刻 T-1 に食べ始めるとき、i-1 までを j(<T) までに獲得できる最大の deliciousness
    vector<vector<int>> dp(N, vector<int>(T));
    int ans = dish[0].second;

    REP(j, T) if(dish[0].first <= j and j < T) dp[0][j] = dish[0].second;
    FOR(i, 1, N){
        REP(j, T){
            ans = max(ans, dp[i-1][j]+dish[i].second);
            dp[i][j] = dp[i-1][j];
        }
        REP(j, T){
            if(dish[i].first <= j and j < T) dp[i][j] = max(dp[i][j], dp[i-1][j-dish[i].first]+dish[i].second);
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 35584
from itertools import accumulate

h, w, d = map(int, input().split())
xys = [[int(x) for x in input().split()] for _ in range(h)]
q = int(input())
lrs = [tuple(map(int, input().split())) for _ in range(q)]

dict_ = {v:(x, y) for y, row in enumerate(xys) for x, v in enumerate(row)}
def jump_cost(xy, ab):
    x, y = dict_[xy]
    a, b = dict_[ab]
    return abs(x-a) + abs(y-b)

m = h * w
d_ = {}
for i in range(1, d+1):
    startend = zip(range(i, m+1, d), range(i+d, m+1, d))
    costs = (jump_cost(xy1, xy2) for xy1, xy2 in startend)
    d_[i % d] = [0] + list(accumulate(costs))

for l, r in lrs:
    a = r // d
    b, c = divmod(l, d)
    print(d_[c][a - (c==0)] - d_[c][b - (c==0)])

Measured memory_bytes: 54256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	int n;
	cin >> n;
	vector<int> l(2 * n);
	for (int i = 0; i < 2 * n;i++) {
		cin >> l[i];
	}

	sort(l.begin(), l.end());
	int sum = 0;
	for (int i = 0; i < 2 * n;i += 2) {
		sum += l[i];
	}
	cout << sum << endl;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200000)

N, M, P = map(int, input().split())

INF = 10**10
# Bellman-Fordをするときは、辺集合を持つ
edges = [] 
# 1から行けない辺やNに到達できない辺を削除するための探索をする用
to = [[] for _ in range(2505)]
rto = [[] for _ in range(2505)]
reachableFrom1 = [False for _ in range(2505)]
reachableToN = [False for _ in range(2505)]
ok = [False for _ in range(2505)]

def dfs(v):
    if reachableFrom1[v]:
        return
    reachableFrom1[v] = True
    for u in to[v]:
        dfs(u)

def rdfs(v):
    if reachableToN[v]:
        return
    reachableToN[v] = True
    for u in rto[v]:
        rdfs(u)

for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1; b -= 1
    c -= P
    c = -c # 最短路にするため符号を逆転
    edges.append([a, b, c])
    to[a].append(b)
    rto[b].append(a)

# 考えるべき頂点だけ洗い出し
dfs(0)
rdfs(N-1)
for i in range(N):
    ok[i] = reachableFrom1[i] & reachableToN[i]

# Bellman-Ford
d = [INF for _ in range(N)]
d[0] = 0
upd = True
step = 0
flag = True
while upd:
    upd = False
    for i in range(M):
        a, b, c = edges[i]
        if not ok[a]:
            continue
        if not ok[b]:
            continue
        newD = d[a]+c
        if newD < d[b]:
            upd = True
            d[b] = newD
    step += 1
    if step > N:
        flag = False
        break
if flag:
    ans = -d[N-1]
    ans = max(ans, 0)
    print(ans)
else:
    print(-1)

Measured memory_bytes: 66160
#include<stdio.h>
void swap(int *x,int *y){
int m=*x;
*x=*y;
*y=m;
}
int main(){
int a[200],n,j,k,i;
while(scanf("%d",&n),n){
j=0;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(k=0;k<n-1;k++)
for(i=0;i<n-1;i++)
if(a[i]>a[i+1]){
swap(&a[i],&a[i+1]);
j++;
}
printf("%d\n",j);

}
return 0;
}

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

using namespace std;

int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> h(n);
	for(int i=0;i<n;i++)
		cin >> h[i];
	
	vector<long long> dp(n,1000000000000000);
	dp[0]=0;
	
	for(int i=0;i<n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			if(i+j>=n)break;
			dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
		}

	}

	cout << dp[n-1] << endl;
}



Measured memory_bytes: 1408
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    vector<int> d;
    for(int i = 1; i <= 100; i++){
        if(A % i == 0 and B % i == 0) d.push_back(i);
    }
    cout << d[d.size() - K] << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

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

using namespace std;

int main(){
    int n, sum = 0; cin >> n;
    int array[n]; REP(i, n) cin >> array[i];

    REP(i, n)
        for(int j = i + 1; j < n; j++)                                 
            sum += array[i] * array[j];

    cout << sum;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;

int main(){

	ll n, a[200000], b[200001], ans=0;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	b[0]=0;
	for(int i=0; i<n; i++){
		b[i+1]=b[i]+a[i];
	}
	sort(b, b+n+1);
	ll c=1;
	for(int i=0; i<n; i++){
		if(b[i]==b[i+1]){
			c++;
		} else {
			ans+=c*(c-1)/2;
			c=1;
		}
	}
	ans+=c*(c-1)/2;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3328
N, A, B, C = list(map(int, input().split()))
l = [int(input()) for _ in range(N)]
INF = 10**12

def dfs(depth, a, b, c):
    if depth == N:
        return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF

    res1 = dfs(depth + 1, a, b, c)
    res2 = dfs(depth + 1, a + l[depth], b, c) + 10
    res3 = dfs(depth + 1, a, b + l[depth], c) + 10
    res4 = dfs(depth + 1, a, b, c + l[depth]) + 10

    return min(res1, res2, res3, res4)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
S = input()
# dream + eraser なのに dreamer を消さないように
# 先に dreamerase(r)を消しておく
# S = S.replace("dreameraser", "") #３回めの提出時に削除
# S = S.replace("dreamerase", "") #３回めの提出時に削除
# S = S.replace("dreamer", "") # ２回めの提出時にeraseの後ろへ
# S = S.replace("dream", "") # ２回めの提出時にeraseの後ろへ
# eraserより先にdreamerを消すとWAになりました
# dreameraserのパターンは消去済みなのに、なんでだろ
S = S.replace("eraser", "")
S = S.replace("erase", "")
S = S.replace("dreamer", "")
S = S.replace("dream", "")

if S == "":
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3188
import math
s = input()
a,b,h,m = s.split(' ')
a = int(a)
b = (int)(b)
h = int(h)
m = int(m)
t1 = h/6 * math.pi + math.pi/6*m/60
t2 = m/30 * math.pi
dellt = abs(t2 - t1)
ans = b*b + a*a - 2*a*b*math.cos(dellt)
print(ans**0.5)


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


int main() {

    int n;
    cin >> n;
    int sum = 0;
    int m = 0;
    rep(i,n) {
        int l; cin >> l;
        sum += l;
        m = max(l, m);
    }
    cout << (m < sum-m ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main(){
    int n;
    cin >> n;
    if(n == 0) cout << 1 << endl;
    else cout << 0 << endl;
}

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

using namespace std;

double n, fact = 1, ans;
pair<double,double> points[8];

int main()
{
    cin >> n;
    for(int i = 0; i<n; i++)
        cin >> points[i].first >> points[i].second;
    for(int i = 0; i<n; i++)
        for(int j = 0; j<n; j++)
            ans+=sqrt((points[i].first-points[j].first)*(points[i].first-points[j].first)+(points[i].second-points[j].second)*(points[i].second-points[j].second))/n;
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}cout<<endl;}



void update(ll i, ll x, vector<ll> &v){
    v[i] = x;
}

ll find(ll s, ll t, vector<ll> &v){
    ll tmp = v[s];
    fr(i, s, t+1) tmp = min(v[i],tmp);
    return tmp;
}

int main() {
    ll n;
    cin>>n;
    vector<ll> v(n);
    rep(i, n) cin>>v[i];
    ll a = *max_element(v.begin(),v.end());
    if (accumulate(v.begin(), v.end(), 0) - a > a) cout << "Yes"<<endl;
    else cout << "No" << endl;
    
}



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

int main()
{
long long N,K,ans;scanf("%lld %lld",&N,&K);
if(N<K)ans=min(N,K-N);
else ans=min(abs((N/K)*K-N),abs(((N/K)+1)*K-N));
printf("%lld\n",ans);
}


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

int ta[1000],tb[1000],tc[1000];
int a,b,c,m,n,cn;


int main(){

  while(cin>>n){
    cin>>m;
    for(int I=0;I<n;I++)tc[I]=I;
    for(int I=0;I<m;I++){
      cin>>c;
      for(int i=0;i<(n/2);i++){
	tb[i]=tc[i];
	//cout<<tb[i]<<' ';
      }
      //cout<<endl;

      for(int i=n/2;i<n;i++){
	ta[i-n/2]=tc[i];
	//cout<<tc[i]<<' ';
      }
      //cout<<endl;
      

      cn=a=b=0;

      while(1){
	for(int i=0;i<c;i++){
	  tc[cn++]=ta[a++];
	  if(cn==n||a==n-n/2)break;
	}
	if(cn==n)break;
	for(int i=0;i<c;i++){
	  tc[cn++]=tb[b++];
	  if(cn==n||b==n/2)break;
	}
	if(cn==n)break;
      }

    }
    cout<<tc[n-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1168