akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y,a,b,c,d;


#include <queue>
//mapの使い方
#include <map>

map<ll,ll> nums;
map<ll,ll> nums2;






    auto compare = [](pair<ll,ll> a, pair<ll,ll> b) {
      if (a.first == b.first){
        return a.second > b.second;
      }
      return a.first > b.first;
    };

priority_queue<
  pair<ll,ll>,
  vector<pair<ll,ll>>,
  decltype(compare) // 比較関数オブジェクトを指定
> que {compare};


void qp(ll score,ll val){
  
  auto it=nums.find(val);
  if (it==nums.end()){
    que.push(make_pair(score,val));
    nums[val]=score;
  }else{
    if (nums[val]>score){
      que.push(make_pair(score,val));
      nums[val]=score;
    }
  }

}


int main(){
  ll ans=0,t;
  cin>>t;

  REP(i,t){

  
    cin >> n >> a>>b>>c>>d;

    nums.clear();
    nums[n]=0;
    que.push(make_pair(0,n));
    
    while (!que.empty()) {
      ll score=que.top().first;
      ll nopw=que.top().second;
      que.pop();
      
      if (nopw%2==0){
        if (nopw<2000000000){
          qp(min(score+a,score+d*(nopw/2)),nopw/2);
        }else{
          qp(score+a,nopw/2);
        }
        
      }else{
        if (nopw<2000000000){
          qp(min(score+a+d,score+d*(nopw-nopw/2)),nopw/2);
          qp(min(score+a+d,score+d*(nopw-nopw/2-1)),nopw/2+1);
        }else{
          qp(score+a+d,nopw/2);
          qp(score+a+d,nopw/2+1);
        }
      }
      
      if (nopw%3==0){
        if (nopw<3000000000){
          qp(min(score+b,score+d*(nopw-nopw/3)),nopw/3);
        }else{
          qp(score+b,nopw/3);
        }
        
      }else{
        if (nopw<3000000000){
          qp(min(score+b+d*(nopw%3),score+d*(nopw-nopw/3)),nopw/3);
          qp(min(score+b+d*(3-(nopw%3)),score+d*(nopw-nopw/3-1)),nopw/3+1);
        }else{
          qp(score+b+d*(nopw%3),nopw/3);
          qp(score+b+d*(3-(nopw%3)),nopw/3+1);
        }
      }
      
      if (nopw%5==0){
        if (nopw<5000000000){
          qp(min(score+c,score+d*(nopw-nopw/5)),nopw/5);
        }else{
          qp(score+c,nopw/5);
        }
        
      }else{
        if (nopw<5000000000){
          qp(min(score+c+d*(nopw%5),score+d*(nopw-nopw/5)),nopw/5);
          qp(min(score+c+d*(5-nopw%5),score+d*(nopw-nopw/5-1)),nopw/5+1);
        }else{
          qp(score+c+d*(nopw%5),nopw/5);
          qp(score+c+d*(5-nopw%5),nopw/5+1);
        }
      }
    
    }


    cout<<nums[0]<<endl;




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

Measured memory_bytes: 4492
N = int(input().rstrip())
A = list(map(int, input().rstrip().split()))

def insertion_sort(A, N):
    for i in range(N):
        key = A[i]
        j = i - 1
        while j >= 0 and A[j] > key:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = key

        string = list(map(str, A))
        print(' '.join(string))

insertion_sort(A, N)      


Measured memory_bytes: 5596
#include<stdio.h>

#define MAX 25
#define ROOT -1
#define NONODE -1

struct NODE {
	int parent;
	int left;
	int right;
};

typedef struct NODE NODE;

NODE nodes[ MAX+1 ];

void walkPreorder( int i )
{
	if( NONODE == i ) { return; }
	
	printf( " %d", i );
	if( NONODE != nodes[i].left ) {
		walkPreorder( nodes[i].left );
	}
	if( NONODE != nodes[i].right ) {
		walkPreorder( nodes[i].right );
	}
	return;
}
void walkInorder( int i )
{
	if( NONODE == i ) { return; }
	
	if( NONODE != nodes[i].left ) {
		walkInorder( nodes[i].left );
	} else if( NONODE == nodes[i].left && NONODE == nodes[i].right ) {
		printf( " %d", i );
		return;
	}
	printf( " %d", i );
	if( NONODE != nodes[i].right ) {
		walkInorder( nodes[i].right );
	}
	return;
}
void walkPostorder( int i )
{	
	if( NONODE == i ) { return; }
	
	if( NONODE != nodes[i].left ) {
		walkPostorder( nodes[i].left );
	} else if( NONODE == nodes[i].left && NONODE == nodes[i].right ) {
		printf( " %d", i );
		return;
	}
	if( NONODE != nodes[i].right ) {
		walkPostorder( nodes[i].right );
	}
	printf( " %d", i );
	
	return;
}

int main( void ) 
{   
    int n;
    int root,left,right,id;
    int i;
	       
    scanf( "%d", &n );

	for( i=0; i<n; i++ ) {
		nodes[i].parent=ROOT;
    }    
    for( i=0; i<n; i++ ) {
    	scanf( "%d%d%d", &id, &left, &right );
	    nodes[id].left=left;
    	if( -1 != left ) {
	    	nodes[left].parent=id;
    	}
	    nodes[id].right=right;
    	if( -1 != right ) {
	    	nodes[right].parent=id;
    	}
    }
    root=ROOT;
	for( i=0; i<n; i++ ) {
        if( ROOT == nodes[i].parent ) {
            root=i;
            break;
        }
     }
	printf( "Preorder\n" );
	walkPreorder( root );
	printf( "\n" );
	
	printf( "Inorder\n" );
	walkInorder( root );
	printf( "\n" );
	
	printf( "Postorder\n" );
	walkPostorder( root );
	printf( "\n" );

    return 0;
}

Measured memory_bytes: 616
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk){
 var x = chunk.split(" ")
 var a = Number(x[0])
 var b = Number(x[1])
 
 if (a == b) {
   console.log("a == b")
 } else if (a < b) {
     console.log("a < b")
   } else
     console.log("a > b")
});

Measured memory_bytes: 15468
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
vector <int> from[100010];
int L[100010], R[100010];
int id[100010];
bool ans;
void solve(int u = 0, int p = -1){
	L[u] = -INF - 1, R[u] = INF + 1;
	if (id[u] != -1) L[u] = R[u] = id[u];
	for (int i = 0; i < from[u].size(); i++){
		int v = from[u][i];
		if (v == p) continue;
		solve(v, u);
		if (L[v] < -INF / 2) continue;
		if (L[u] < -INF / 2) L[u] = L[v] - 1, R[u] = R[v] + 1;
		else {
			if (abs(L[v]) % 2 == abs(L[u]) % 2){
				ans = 0;
				return ;
			}
			L[u] = max(L[u], L[v] - 1);
			R[u] = min(R[u], R[v] + 1);
		}
	}
	if (L[u] > R[u]) ans = 0;
}
void make(int v = 0, int p = -1){
	if (v == 0 && id[v] == -1) id[v] = L[v];
	for (int i = 0; i < from[v].size(); i++){
		int to = from[v][i];
		if (to == p) continue;
		if (id[to] == -1){
			if (L[to] <= id[v] - 1 && id[v] - 1 <= R[to]) id[to] = id[v] - 1;
			else id[to] = id[v] + 1;
		}
		make(to, v);
	}
}
int main(){
	int n;
	scanf("%d", &n);
	for (int i = 1; i < n; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		a--, b--;
		from[a].push_back(b);
		from[b].push_back(a);
	}
	memset(id, -1, sizeof(id));
	int m;
	scanf("%d", &m);
	for (int i = 0; i < m; i++){
		int v, p;
		scanf("%d%d", &v, &p);
		v--, id[v] = p;
	}
	ans = 1;
	solve();
	if (!ans){
		puts("No");
		return 0;
	}
	make();
	puts("Yes");
	for (int i = 0; i < n; i++){
		printf("%d\n", id[i]);
	}
	return 0;
}

Measured memory_bytes: 15360
from sys import stdin
input = stdin.readline

def main():
    N = int(input())
    reward = [list(map(int, input().split())) for _ in range(N)]
    
    dp = [[0] * 3 for _ in range(N)]
    dp[0] = reward[0]
    
    for i in range(1, N):
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + reward[i][0]
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + reward[i][1]
        dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + reward[i][2]
    
    print(max(dp[-1]))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 47280
class in{struct my_iterator{int it;const bool rev;explicit constexpr my_iterator(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(my_iterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const my_iterator i,n;public:explicit constexpr in(int n):i(0),n(n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const my_iterator& begin(){return i;}const my_iterator& end(){return n;}};

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

using i64 = long long;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, k; cin >> n >> k;
    vector<vector<int>> books(10);
    for(int _ : in(n)) {
        int c, g;
        cin >> c >> g;
        --g;
        books[g].emplace_back(c);
    }
    vector<i64> dp(k + 1, -1e12);
    dp[0] = 0LL;
    for(auto& book : books) {
        sort(book.rbegin(), book.rend());
        i64 sum = 0;
        auto dp_ = dp;
        for(i64 i : in(book.size())) {
            sum += book[i];
            for(int j : in(k + 1)) if(dp[j] >= 0) {
                int x = i + 1 + j;
                if(x > k) continue;
                dp_[x] = max(dp_[x], dp[j] + sum + i * (i + 1));
            }
        }
        dp = dp_;
    }
    cout << dp[k] << endl;
    return 0;
}

Measured memory_bytes: 3204
#include<cstdio>
#include<cstring>
#define P 1000000007
#define N 2000005

int n,m;
char s[N];

int fac[N],inv[N],pw1[N],pw2[N];

int ans;

int main(){
	scanf("%d%s",&n,s+1);
	m=strlen(s+1);
	n+=m;
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=1ll*fac[i-1]*i%P;
	inv[0]=inv[1]=1;
	for(int i=2;i<=n;i++)
		inv[i]=(P-1ll*P/i*inv[P%i]%P)%P;
	for(int i=2;i<=n;i++)
		inv[i]=1ll*inv[i-1]*inv[i]%P;
	pw1[m]=1;
	for(int i=m+1;i<=n;i++)
		pw1[i]=1ll*pw1[i-1]*25%P;
	pw2[n]=1;
	for(int i=n-1;i;i--)
		pw2[i]=1ll*pw2[i+1]*26%P;
	for(int i=m;i<=n;i++)
		ans=(ans+1ll*fac[i-1]*inv[m-1]%P*inv[i-m]%P*pw1[i]%P*pw2[i]%P)%P;
	printf("%d",ans);
}

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

int main() {
    int n;
    ll ans = 0;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());
    ans += a[0];
    int idx1 = 0, idx2 = 1;
    for (int i = 2; i < n; ++i) {
        if (i % 2 == 1) {
            ans += min(a[idx1], a[idx2]);
            idx1++;
            idx2++;
        } else {
            ans += min(a[idx1], a[idx2]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4004
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  string s;
  cin >> s;
  if (s.substr(0, 4) == "YAKI") cout << "Yes" << '\n';
  else cout << "No" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3644
n = int(input())
a = [int(i) for i in input().split()]

for i in range(n):
    if a[i]%2 == 0:
        if a[i]%3 != 0 and a[i]%5 != 0:
            print("DENIED")
            exit()
        else:
            continue
    else:
        continue

print("APPROVED")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++)
#define FORD(i, a, b) for (int i = (a), i##_len = (b); i > i##_len; i--)
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

int ctoi(char c) {
    switch (c) {
        case '0':
            return 0;
        case '1':
            return 1;
        case '2':
            return 2;
        case '3':
            return 3;
        case '4':
            return 4;
        case '5':
            return 5;
        case '6':
            return 6;
        case '7':
            return 7;
        case '8':
            return 8;
        case '9':
            return 9;
        default:
            return 0;
    }
}

int main() {
    string s;
    int n, m, ans;
    cin >> s;
    ans = 0;
    m = 2019;
    n = s.size();
    vector<int> dp(m, 0);
    REP(i, n) {
        int ii;
        ii = ctoi(s[i]);
        dp[0] += 1;
        vector<int> dp2(m, 0);
        REP(j, m){
            dp2[(j * 10 + ii) % m] += dp[j];
        }
        dp = dp2;
        ans += dp[0];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3716
from sys import stdin
n,W=map(int,input().split())
dp=[0 for i in range(W+1)]
for i in range(n):
    w,v=map(int,stdin.readline().split())
    for j in range(W-w,-1,-1):
        dp[j+w]=max(dp[j]+v,dp[j+w])
print(dp[-1])

Measured memory_bytes: 45680
n=int(input())
a=[int(input()) for i in range(n)]
a=sorted(a)
for i in range(n):
    if sum(a)%10!=0:
        print(sum(a))
        exit()
    else:
        frag=True
        for j in a:
            if j%10!=0 and frag==True:
                a.remove(j)
                frag=False
print(0)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
	double xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2;
	while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &xa1, &ya1, &xa2, &ya2, &xb1, &yb1, &xb2, &yb2) != EOF) {
		if (xa2 < xb1 || xa1 > xb2) {
			puts("NO");
		}
		else if (ya2 < yb1 || ya1 > yb2) {
			puts("NO");
		} else {
			puts("YES");
		}
	}
	return 0;
}

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

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)
        {
            var r =int.Parse( Console.ReadLine() );
            Console.WriteLine(r*r);

        }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
int n;
const long long int mod = 1000000007;
long long int fct[1001000];
long long int ifct[1001000];
long long int mpow(long long int x, long long int y) {
	if (y == 0)return 1;
	long long int r = mpow(x, y / 2);
	r *= r;
	r %= mod;
	if (y % 2 == 1) {
		r *= x;
		r %= mod;
	}
	return r;
}
long long int comb(int x, int y) {
	return (fct[x] * ifct[y] % mod)*ifct[x - y] % mod;
}
int main() {
	scanf("%d", &n);
	fct[0] = 1;
	for (int i = 1; i <= n; i++) {
		fct[i] = fct[i - 1] * i % mod;
	}
	ifct[n] = mpow(fct[n], mod - 2);
	for (int i = n; i > 0; i--) {
		ifct[i - 1] = ifct[i] * i % mod;
	}
	long long int ans = 0;
	for (int i = (n + 1) / 2; i < n; i++) {
		ans += comb(i - 1, 2 * i - n)*fct[i] % mod * fct[n - 1 - i] % mod;
		ans %= mod;
	}
	ans = fct[n] + (mod - ans);
	ans %= mod;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 15744
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll H,A;
int main(){
    cin>>H>>A;
    cout<<(H-1)/A+1<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;
typedef long long int lli;



int main(void)
{
	int N; cin >> N;
	bool flag = false;
	rep(i, 0, N / 7 + 1) {
		if ((N - 7 * i) % 4 == 0) {
			flag = true;
			break;
		}
	}
	cout << (flag ? "Yes" : "No") << endl;

	return 0;
}

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

string N;
int i;

int main(void) {
    cin >> N;
    
    int ans = 0;
    for (i=0; i<N.size(); i++) {
        if (N[i] == '2') {
            ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		
		int N=sc.nextInt();
		int[] a = new int[N];
		int sum=0;
		for(int i=0;i<N;i++) {
			a[i]=sc.nextInt();
			sum+=a[i]-1;
		}
		System.out.println(sum);
	}

}


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

int main(){
    vector<int> menu(5);
    int count = 0, ans = 0 , max = 0;

    for(int i = 0; i <5; i++){
    cin >> menu.at(i);
    }
    for(int i =0; i < 5; i++){
        for(int k =0; k < 11; k++){
            if(menu.at(i)%10 == 0){
                count = 0;
                break;
            }else{
                menu.at(i)++;
                count++;
                if(max < count){
                    max++;
                }
            }
        }
    }
    for(int i = 0; i < 5; i++){
        // cout << menu.at(i) << endl;
        ans = ans + menu.at(i);
    }
    cout << ans - max;
}

Measured memory_bytes: 256
import sys
read = lambda: sys.stdin.readline().rstrip()
 
def main():
    INF = 10 ** 20
 
    n,k = map(int,input().split())
    height = tuple(map(int,read().split()))
    dp = [INF]*(n+1)
    dp[0] = 0
 
    for target in range(1, n):
        for step in range(1, k + 1):
            if target-step >= 0: dp[target] = min(dp[target], dp[target - step] + abs(height[target] - height[target - step]))
 
    print(dp[n-1])

if __name__ == "__main__":
    main()

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

#define int long long
#define MAX 210000

int n;
int a[MAX];
deque<int> d;

signed main(){


  cin>>n;

  
  for(int i = 0, f = !(n%2); i < n; i++){
    cin>>a[i];
    if(f == 0){
      d.push_front(a[i]);
      f = 1;
    } else {
      d.push_back(a[i]);
      f  = 0;
    }
  }

  for(int i = 0; i < n; i++){
    if(i)cout<<" ";
    cout<<d[i];
  }
  cout<<endl;
  
  return 0;
}


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

int n;
string s,t;
int main(){
	cin >> n;
	int a = 0,b = 0;
	for(int i=0;i<n;i++){
		cin >> s >> t;
		if(s>t) a += 3;
		else if(s<t) b += 3;
		else {a++;b++;}
	}
	printf("%d %d\n",a,b);
}


Measured memory_bytes: 3284
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int, Z: int):
    print("{} {} {}".format(Z,X,Y))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    solve(X, Y, Z)

if __name__ == '__main__':
    main()


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a.at(i);
  }
  
  int A,B;
  A=0; B=0;
  bool turn = true;
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=0; i<N; i++){
    if(turn){
      A += a.at(i);
      turn = false;
    }else{
      B += a.at(i);
      turn = true;
    }
  }
  cout << A-B << endl;
}


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

const char stand = '0';
const char handstand = '1';
int N, K;
string S;

int main(void) {
  cin >> N >> K;
  cin >> S;

  vector<int> nums;
  char cur = handstand;
  int cnt = 0;

  // C0: chunk of 0
  // C1: chunk of 1
  // make C1, C0, C1, C0...C1
  for (int i = 0; i < N; i++) {
    if (S[i] == cur) {
      cnt++;
    } else {
      nums.push_back(cnt);
      cnt = 1;
      cur = S[i];
    }
  }
  if (cnt != 0)
    nums.push_back(cnt);

  if (nums.size() % 2 == 0)
    nums.push_back(0);

  vector<int> sums(nums.size() + 1);
  for (int i = 0; i < nums.size(); i++) {
    sums[i + 1] = sums[i] + nums[i];
  }

  // C1, C0, C1, C0...C1
  const int addindex = 2 * K + 1;
  int ans = 0;
  for (int i = 0; i < nums.size(); i += 2) {

    int left = i;
    int right = min(i + addindex, (int)nums.size());
    int tmp = sums[right] - sums[left];

    ans = max(tmp, ans);
  }

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


Measured memory_bytes: 1272
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double x = 0;
		double y = 0;
		int theta = 0;
		for(;;){
			String s = sc.nextLine();
			if(s.equals("0,0")){
				break;
			}
			int a = Integer.parseInt(s.substring(0,s.indexOf(",")));
			int b = Integer.parseInt(s.substring(s.indexOf(",")+1,s.length()));
			if(a==0&&b==0){
				break;
			}
			y+=a*Math.cos(Math.toRadians(theta));
			x+=a*Math.sin(Math.toRadians(theta));
			theta += b;
		}
		int xx = (int) x;
		int yy = (int) y;
		System.out.println(xx);
		System.out.println(yy);
	}

}

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

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

#define INF 2e9
#define ALL(v) v.begin(), v.end()

int k;
int memo[200+1][200+1];

int gcd(int x,int y){
    if(y==0){
        return x;
    }
    return gcd(y,x%y);
}

int main(){
    cin>>k;
    int ans=0;
    for(int a=1;a<=k;a++){
        for(int b=1;b<=k;b++){
            for(int c=1;c<=k;c++){
                ans+=gcd(gcd(a,b),c);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000003 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 2000010;
ll t[N << 1];
int sze;

void init(int n){
	sze = n;
	cu(i,0,n)t[i + n] = i + 1;
	cd(i,n,1){
		t[i] = t[i<<1] * t[i<<1|1] % MOD;	
	}
}

ll query(int l,int r){
	ll res = 1;	
	for(l+=sze,r+=sze;l < r;l>>=1,r>>=1){
		if(l&1)res = res * t[l++] % MOD;
		if(r&1)res = res * t[--r] % MOD;
	}
	return res;
}

ll modpow(ll x, ll p){
	if(p == 0)return 1;
	ll y = 1;
	while(p > 1){
		if(p&1)y = y * x % MOD;
		x = x * x % MOD;
		p>>=1;
	}
	return x * y % MOD;
}

int main(){
	fast_io();
	init(MOD * 2);
	int q;
	cin >> q;
	cu(i,0,q){
		ll x,d,n;
		cin >> x >> d >> n;
		if(d == 0){
			cout << modpow(x,n) << '\n';
		}
		else if(n >= MOD){
			cout << 0 << '\n';
		}
		else{
			ll ans = modpow(d,n);
			ll start = x * modpow(d,MOD-2) % MOD;
			ans *= query(start-1,start+n-1);
			ans %= MOD;
			cout << ans << '\n';
		}
	}
}


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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)
ll A[(ll) (2*10e5+5)];
ll ANS[(ll) (2*10e5+5)];

int main(){
    ll N;
    ll Ai;
    cin >> N;
    FOR(i,2,N) {
        cin >> Ai;
        ANS[Ai] += 1;
    }
    FOR(i,1,N) {
        cout << ANS[i];
        cout << endl;
    }
}

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

long long knapsack(vector<pair<long long,long long>> v, vector<vector<long long>> &sol, long long n,long long c) {
	/*if(sol[n][c] == INT_MIN) {
		sol[n][c] = knapsack(v,sol, n-1, c);
		if(c-v[n-1].second >= 0) {
			sol[n][c] = max(sol[n][c], v[n-1].first + knapsack(v,sol, n-1, c-v[n-1].second));
		}
	}*/

	for(long long i=1; i<n+1; i++) {
		for(long long j = 1; j<c+1; j++) {
			sol[i][j] = max(sol[i-1][j], j-v[i-1].second >=0 ? v[i-1].first + sol[i-1][j-v[i-1].second]: INT_MIN);
		}
	}
	return sol[n][c];
}
int main() {
	long long n, c;
	cin>>n>>c;
	vector<pair<long long,long long> > v(n);
	for(long long i=0; i<n; i++) {
		cin>>v[i].second;
		cin>>v[i].first;
	}

	vector<long long> temp(c+1, LLONG_MIN);
	vector< vector<long long> > sol;
	for(long long i=0; i<n+1; i++)
		sol.push_back(temp);

	for(long long i=0; i<n+1; i++) {
		sol[i][0] = 0;
	}
	for(long long i=0; i<c+1; i++) {
		sol[0][i] = 0;
	}

	cout<<knapsack(v, sol, n, c)<<endl;
}

Measured memory_bytes: 80256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int n, m;
		double per;
		int sum = 0;
		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();
		m = scan.nextInt();

		int array[] = new int[n];
		double array_per[] = new double[n];

		for(int i = 0; i < n; i++) {
			array[i] = scan.nextInt();
			sum += array[i];
		}

		per = 1.0/(4*m);

		for(int i = 0; i < n; i++) {
			array_per[i] = (double)array[i]/sum;
		}

		int count = 0;
		for(int i = 0; i < n; i++) {
			if(array_per[i] >= per) {
				count++;

				if(count >= m) {
					System.out.println("Yes");
					break;
				}
			} else {
				if(i == n-1) {
					System.out.println("No");
				}
			}
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
typedef vector<ll> lvec;typedef vector<double> dvec;typedef vector<string> svec;
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
  ll n, sum=0; cin>>n;
  ll N=n;
  while(n>0){
    sum += n%10;
    n/=10;
  }
  if(N%sum==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main(){
int n;cin>>n;
  int maxp=0,ans=0;
  
for(int i=0;i<n;i++)
{
  int p;cin>>p;
  maxp=max(p,maxp);
  ans+=p;
}
  cout<<ans-maxp/2<<endl;
}


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

using namespace std;

template< typename flow_t, typename cost_t >
struct PrimalDual {
  const cost_t INF;

  struct edge {
    int to;
    flow_t cap;
    cost_t cost;
    int rev;
  };
  vector< vector< edge > > graph;
  vector< cost_t > potential, min_cost;
  vector< int > prevv, preve;

  PrimalDual(int V) : graph(V), INF(numeric_limits< cost_t >::max()) {}

  void add_edge(int from, int to, flow_t cap, cost_t cost) {
    graph[from].emplace_back((edge) {to, cap, cost, (int) graph[to].size()});
    graph[to].emplace_back((edge) {from, 0, -cost, (int) graph[from].size() - 1});
  }

  cost_t min_cost_flow(int s, int t, flow_t f) {
    int V = (int) graph.size();
    cost_t ret = 0;
    using Pi = pair< cost_t, int >;
    priority_queue< Pi, vector< Pi >, greater< Pi > > que;
    potential.assign(V, 0);
    preve.assign(V, -1);
    prevv.assign(V, -1);

    while(f > 0) {
      min_cost.assign(V, INF);
      que.emplace(0, s);
      min_cost[s] = 0;
      while(!que.empty()) {
        Pi p = que.top();
        que.pop();
        if(min_cost[p.second] < p.first) continue;
        for(int i = 0; i < graph[p.second].size(); i++) {
          edge &e = graph[p.second][i];
          cost_t nextCost = min_cost[p.second] + e.cost + potential[p.second] - potential[e.to];
          if(e.cap > 0 && min_cost[e.to] > nextCost) {
            min_cost[e.to] = nextCost;
            prevv[e.to] = p.second, preve[e.to] = i;
            que.emplace(min_cost[e.to], e.to);
          }
        }
      }
      if(min_cost[t] == INF) return -1;
      for(int v = 0; v < V; v++) potential[v] += min_cost[v];
      flow_t addflow = f;
      for(int v = t; v != s; v = prevv[v]) {
        addflow = min(addflow, graph[prevv[v]][preve[v]].cap);
      }
      f -= addflow;
      ret += addflow * potential[t];
      for(int v = t; v != s; v = prevv[v]) {
        edge &e = graph[prevv[v]][preve[v]];
        e.cap -= addflow;
        graph[v][e.rev].cap += addflow;
      }
    }
    return ret;
  }
};

int main() {
  int V, E, F;
  scanf("%d %d %d", &V, &E, &F);
  PrimalDual< int, int > g(V);
  for(int i = 0; i < E; i++) {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    g.add_edge(a, b, c, d);
  }
  printf("%d\n", g.min_cost_flow(0, V - 1, F));
}


Measured memory_bytes: 3304
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
#define pb push_back
#define ppb pop_back

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

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

const int N = 1e5 + 667;
int a[N];

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

    for(int i = 0;i<3;i++){
        cin >> a[i];
    }
    sort(a, a+3);
    if((a[0] == a[1] && a[1] != a[2]) || (a[1] == a[2] && a[0] != a[1])){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	string s;
	cin>>n>>s;
	ll r=0,g=0,b=0;
	for(auto c:s){
		if(c=='R') r++;
		else if(c=='G') g++;
		else b++;
	}
	ll res=r*g*b;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(s[i]==s[j]) continue;
			int k=(j-i)+j;
			if(k>=n||s[k]==s[i]||s[k]==s[j]) continue;
			res--;
		}
	}
	cout<<res<<'\n';
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const ll mod     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 10000 + 10;
const ll N2      = 70;
const ld PI      = 3.141592653589793;
//template<class T>using onset=tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
  #ifndef ONLINE_JUDGE  
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
signed main(){
    fastio();
    //cout<<fixed<<setprecision(20);
    ll n; 
    cin>>n; 
    ll a[n];
    for(ll i=0;i<n;i++){
      cin>>a[i];
    }
    ll ans=a[0],sum=0;
    for(ll i=1;i<n;i++){
      if(a[i]>=ans){
        ans=a[i];
      }
      else{
        sum+=abs(ans-a[i]);
      }
    }
    cout<<sum; 
    //printclock;
    return 0;
}
    

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

int main(){
  int n,k;
  cin >> n >> k;
  map<int,int> a;
  rep(i,n){
    int num;
    cin >> num;
    a[num]++;
  }
  if( a.size() <= k ){
    cout << 0 << endl;
    return 0;
  }
  
  vector<int> v(a.size());
  int c=0;    
  for( auto p : a ){
    v.at(c) = p.second;
    c++;
  }
  sort(v.begin(),v.end());
  int ans = 0;
  rep(i,a.size()-k){
    ans += v.at(i);
  }
  cout << ans << endl;
  return 0;
}


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

namespace ConsoleApp70
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NK = Console.ReadLine().Split(' ');
            int N = int.Parse(NK[0]);
            int K = int.Parse(NK[1]);

            long answer = K;
            for(int i = 1; i < N; i++)
            {
                answer *=(K - 1);
            }

            Console.WriteLine(answer);

        }
    }
}

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

int main(void) {
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	int x[N], y[M];

	for (int i = 0; i < N; i++) cin >> x[i];
	for (int i = 0; i < M; i++) cin >> y[i];
	
	sort(x, x + N);
	sort(y, y + M);
	int a, b;
	a = x[N - 1];
	b = y[0];
	int ave = (a+1 + b) / 2;
	if (((X < ave) && (ave <= Y)) && ((a < ave) && (b >= ave))) {
		cout << "No War" << endl;
	}
	else {
		cout << "War" << endl;
	}
	return 0;

}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=1e6+5,M=2e6+5,MOD=1e9+7,OO=1e9;

int root[N],sz[N];
int find(int u){
	if(root[u]==u)return u;
	return root[u]=find(root[u]);
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();
	
	int n,m,k;

	scanf("%d %d %d",&n,&m,&k);
	for(int i=1;i<=n;i++)root[i]=i,sz[i]=1;
	std::vector<int> del(n+1,1);
	for(int i=0,x,y;i<m;i++){
		scanf("%d %d",&x,&y);
		del[x]++;
		del[y]++;
		int p1 = find(x) , p2 = find(y);
		if(p1 != p2){
			root[p2]=root[p1];
			sz[p1]+=sz[p2];
		}
	}

	for(int i=0,x,y;i<k;i++){
		scanf("%d %d",&x,&y);
		int p1 = find(x) , p2 = find(y);
		if(p1==p2){
			del[x]++;
			del[y]++;
		}
	}

	for(int i=1;i<=n;i++){
		int p = find(i);
		printf("%d ",sz[p]-del[i]);
	}
}		



Measured memory_bytes: 6272
#include <iostream>
#include<set>
#include<math.h>
#include<list>
#include<vector>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)



int main(){
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    int A[40], B[40], C[40];
    int sumA, sumB, sumC;
    sumA=0;sumB=0;sumC=0;
    rep(i, N){
        cin >> A[i] >> B[i] >> C[i];
        sumA+=A[i];sumB+=B[i];sumC+=C[i];
    }
    int dp[N+1][sumA+1][sumB+1];
    rep(i, N+1){
        rep(ca, sumA+1){
            rep(cb, sumB+1){
                dp[i][ca][cb]=sumC*2;
            }
        }
    }
    dp[0][0][0]=0;

    rep(i, N){
        // cout << i << endl;
        rep(ca, sumA){
            rep(cb, sumB){
                if(dp[i][ca][cb]<dp[i+1][ca][cb])dp[i+1][ca][cb]=dp[i][ca][cb];
                if(ca+A[i]>sumA | cb+B[i]>sumB)continue;
                int ta = ca+A[i];
                int tb = cb+B[i];
                if(dp[i+1][ta][tb]>dp[i][ca][cb]+C[i])dp[i+1][ta][tb]=dp[i][ca][cb]+C[i];
            }
        }
    }
    int ans = sumC*2;
    int a, b;
    a=Ma;b=Mb;
    while(a<=sumA & b<=sumB){
        // cout << a << " " << b << " " << dp[N][a][b] << endl;
        if(dp[N][a][b]<ans)ans=dp[N][a][b];
        a+=Ma;b+=Mb;
    }
    if(ans==sumC*2){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }


    return 0;
}


Measured memory_bytes: 9472
#include "bits/stdc++.h"

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int n,m;
int pass[200][200];


int dijk(int s,int g){
    bool used[200]={};
    int d[200];
    rep(i,200)d[i]=INF;
    
    d[s]=0;
    while(1){
        int v=-1;
        rep(u,n){
            if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
        }
        if(v==-1)break;
        
        used[v]=true;
        rep(u,n){
            d[u] = min(d[u],d[v]+pass[v][u]);
        }
    }
    return d[g];
}

int main(){
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        rep(i,200)rep(j,200)pass[i][j]=INF;
        rep(i,m){
            int type;
            cin>>type;
            if(type==0){
                int a,b;
                cin>>a>>b;
                a--,b--;
                int res = dijk(a,b);
                if(res==INF)cout<<"-1"<<endl;
                else cout<<res<<endl;
            
            }else{
                int c,d,e;
                cin>>c>>d>>e;
                c--,d--;
                pass[c][d] = min(pass[c][d],e);
                pass[d][c] = min(pass[d][c],e);
            }
        }
    }
}

Measured memory_bytes: 1320
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
const int N=2e5+5;
const int mod=1e9+7;

int main(){
    int d,n,sum=0;
    cin>>d>>n;
    rep(i,n) {int a;cin>>a;sum+=a;}
    if(sum>d) cout<<"-1"<<endl;
    else cout<<d-sum<<endl;
return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, x, s=0, xk;
  cin >> N >> K;
  for(int i=0;i<N;i++){
    cin >> x;
    xk=x-K;
    if(xk<0) xk=-xk;
    if(x>xk) s+=2*xk; else s+=2*x;
  }
  cout << s << endl; 
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>

using namespace std;

int main(){
    int N; cin >> N;
    int ans = 0;
    while (N > 0){
        if (N % 10 == 2) ans ++;
        N = N / 10;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
MODE = "stdio"
require 'matrix'

tmp = Array.new

class Integer
  def divisor_list2
    return [1] if self == 1
    (1..Math.sqrt(self).to_i).select do |i|
      self%i == 0
    end.map {|e| [e, self/e]}.flatten.uniq.sort
  end
end

if(defined? MODE)
  tmp = STDIN.read.split("\n")
else
  iotmp = "\
  3 8 1
  ".split("\n")
  iotmp.each{|s|
    tmp << s.strip
  }
end


class Three
  def initialize(a,b,c)
    @a = a
    @b = b
    @c = c
  end

  def display
    r = Array.new
    r = [@a, @b, @c]
    if (r[0]>r[1])
      r[0],r[1]=r[1],r[0]
    end
    if (r[1]>r[2])
      r[1],r[2]=r[2],r[1]
    end
    if (r[0]>r[1])
      r[0],r[1]=r[1],r[0]
    end
    print r[0]," ", r[1]," ", r[2],"\n"
  end
end


a,b,c = tmp[0].split(" ").map(&:to_i)

num = Three.new(a,b,c)

num.display

Measured memory_bytes: 9264
from collections import deque
s=deque(list(input()))
q=int(input())
direction=0 #0:順 1:逆

for i in range(q):
    query=list(input().split())
    i=int(query[0])
    if i==1:
        direction=direction^1
    elif i==2:
        f,c=int(query[1]),query[2]
        if f==1 and direction==0:
            s.appendleft(c)
        elif f==1 and direction==1:
            s.append(c)
        elif f==2 and direction==0:
            s.append(c)
        elif f==2 and direction==1:
            s.appendleft(c)

if direction==0:
    print(''.join(s))
else:
    s=''.join(s)
    s=s[::-1]
    print(s)


Measured memory_bytes: 8548
N, M = map(int, input().split())
a = []
b = []
for i in range(M):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

graf = [[] for i in range(N)]

for i in range(M):
    graf[a[i] - 1].append(b[i] - 1)
    graf[b[i] - 1].append(a[i] - 1)

cnt = 0

def sarch(v, graf_check):
    global cnt
    check = list(graf_check)
    check[v] = 1
    #print(v, graf_check)
    if sum(check) == N:
        cnt += 1
    else:
        for i in graf[v]:
            if graf_check[i] == 0:
                sarch(i, check)
                
sarch(0, [0 for i in range(N)])
print(cnt)


Measured memory_bytes: 3064
import java.util.Scanner;
import java.io.*;

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while (true) {
			int n = scan.nextInt();
			if (n == 0) break;
			int[] s;
			s = new int[n];
			int sum = 0;
			for (int i = 0; i < n; i ++) {
				s[i] = scan.nextInt();
				sum += s[i];
			}
			double m = (double)sum / n;
			double shiguma = 0;
			for (int i = 0; i < n; i ++) shiguma += (s[i] - m) * (s[i] - m);
			double a = Math.sqrt(shiguma / n);
			System.out.printf("%f\n", a);
		}
	}
}

Measured memory_bytes: 31452
def main():
    N=int(input())
    L1=[]
    L2=[]
    for i in range(N):
        s,t=input().split()
        t=int(t)
        L1.append(s)
        L2.append(t)
    X=input()
    print(sum(L2[L1.index(X)+1:]))

main()


Measured memory_bytes: 38384
n, a = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
dp = list([0]*(n*a+1) for _ in range(n+1))#動的計画法で解く
dp[0][0] = 1
for x in l:
    for i in range(n, 0, -1):#下行から順に格納していく(上からだと格納したばかりの値が参照されてしまう)
        for j in range(n*a+1):
            if x > j:
                continue
            dp[i][j] += dp[i-1][j-x]

for i in range(n):
    ans += dp[i+1][(i+1)*a]

print(ans)

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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long y,const mint& m){ return m+y; }
mint operator*(long long y,const mint& m){ return m*y; }

mint fact(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		for(;k<=n;k++) memo[k]=memo[k-1]*k;
	}
	return memo[n];
}

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

	vector<int> dif(2*n);
	dif[0]=(s[0]=='W'?0:1);
	rep(i,2*n-1) dif[i+1]=(s[i+1]==s[i]?0:1);

	if(dif[0]==0) return puts("0"),0;

	mint ans=fact(n);
	int cnt=1;
	char prev='[';
	for(int i=1;i<2*n;i++){
		char next;
		if(dif[i]==0) next=(prev=='['?']':'[');
		else          next=prev;
		if(next=='[') cnt++;
		else          ans*=cnt, cnt--;
		prev=next;
	}
	if(cnt!=0) ans=0;
	cout<<ans<<'\n';

	return 0;
}


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

string str = "',.!?abcABCdefDEFghiGHIjklJKLmnoMNOpqrsPQRStuvTUVwxyzWXYZ";

char ch(int key,int n){
    int t = 0;
    
    switch(key){
        case 1:
            return str[n-1+t];
        case 2:
            t = 5;
            return str[n-1+t];
        case 3:
            t = 11;
            return str[n-1+t];
        case 4:
            t = 17;
            return str[n-1+t];
        case 5:
            t = 23;
            return str[n-1+t];
        case 6:
            t = 29;
            return str[n-1+t];
        case 7:
            t = 35;
            return str[n-1+t];
        case 8:
            t = 43;
            return str[n-1+t];
    }
    t = 49;
    return str[n-1+t];
}

int main(){
    string s;
    
    while(cin >> s){
        int len = s.size();
        
        int k = 0;
        if(s[len-1]!='0'){
            s += '0';
            k = 1;
        }
        
        char tmp=s[0]; int cnt = 1;
        string ans = "";
        for(int i = 1 ; i < len+k ; i++){
            if(tmp == s[i]) cnt++;
            else if(tmp != s[i]){
                if(tmp != '0'){
                    ans += ch(tmp-'0',cnt);
                }
                else{
                    if(cnt==2){
                        ans += " ";
                    }
                    else if(cnt==3){
                        ans += "  ";
                    }
                }
                tmp = s[i];
                cnt = 1;
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1196
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

constexpr bool isPrime(const int &n) {
  if (n == 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}

void solve() {
  int n;
  while (cin >> n, n) {
    int c = 0;
    for (int i = n + 1; i <= 2 * n; i++) c += isPrime(i);
    cout << c << endl;
  }
}

Measured memory_bytes: 3076
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 100005
#define P 1000000007
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
using namespace std;

int n, ans=1, num[MAXN];
char s[MAXN];

int main()
{
    scanf("%d", &n);
    scanf("%s", s+1);
    for(rint i=1; i<=n; ++i) num[s[i]-'a']++;
    for(rint i=0; i<26; ++i) ans=1LL*ans*(num[i]+1)%P;
    printf("%d\n", ans-1);
    return 0;
}

Measured memory_bytes: 256