akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

LL dist[201][201];

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

	vector<int> R(r);

	for (int i = 0; i < r; i++) {
		cin >> R[i];
		R[i]--;
	}
	
	//各頂点の距離を初期化
	//自身との距離はゼロ
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			dist[i][j] = (i == j ? 0 : INF);
		}
	}

	for (int i = 0; i < m; i++) {
		int a, b; LL c;
		cin >> a >> b >> c;
		a--; b--;
		dist[a][b] = dist[b][a] = c;
	}

	//WF
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}

	LL ans = INF2;

	//r1,r2,…,rからなる順列が順番に入る。
	//始点と終点を指定すれば最短距離が得られるようになってるから
	//作った順列から点をつないで全部巡った時の距離を求めて
	//どの順番で巡ったときが一番短いか調べていく。

	//nextpermutationはソートしないと途中で終わってしまう。
	sort(R.begin(), R.end());

	do {
		LL sum = 0;

		
		//始点-終点の組
		//このiは今始点なので
		//r-2まででよい。

		//0123だったらr=4まで
		//r=0,r=1,r=2で終わり。
		for (int i = 0; i < r - 1; i++) {
			sum += dist[R[i]][R[i + 1]];
		}

		ans = min(ans, sum);

	
	} while (next_permutation(R.begin(), R.end()));

	cout << ans << endl;
}

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

const long long INFTY = 1e15;

struct Edge {
  int to;
  long long distance;
};

vector<long long> dijkstra(const vector<vector<Edge>>& graph, int source) {
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
  vector<long long> dist(graph.size(), INFTY);
  q.push(make_pair(0, source));
  dist[source] = 0;
  while (!q.empty()) {
    pair<long long, int> front = q.top(); q.pop();
    long long d = front.first;
    int v = front.second;
    // Lazy deletion.
    if (d > dist[v]) {
      continue;
    }
    // Relax edges.
    for (int i = 0; i < graph[v].size(); ++i) {
      if (dist[graph[v][i].to] > d + graph[v][i].distance) {
        dist[graph[v][i].to] = d + graph[v][i].distance;
        q.push(make_pair(dist[graph[v][i].to], graph[v][i].to));
      }
    }
  }
  return dist;
}

int main() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  --s; // 0-indexing
  --t; // 0-indexing
  vector<vector<Edge>> graph1(n);
  vector<vector<Edge>> graph2(n);

  for (int i = 0; i < m; ++i) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    --u; // 0-indexing
    --v; // 0-indexing
    graph1[u].push_back({ v, a });
    graph1[v].push_back({ u, a });
    graph2[u].push_back({ v, b });
    graph2[v].push_back({ u, b });
  }

  // Distance from source to city i, without exchanging money.
  // Distance from target to city i, without exchanging money.
  vector<long long> distance_from_source = dijkstra(graph1, s);
  vector<long long> distance_from_target = dijkstra(graph2, t);

  // Distance from source to target, with exchanging money at
  // city i.
  vector<long long> total_distance(n);
  for (int i = 0; i < n; ++i) {
    total_distance[i] = distance_from_source[i] + distance_from_target[i];
  }

  // Minimum distance from source to target at year i.
  vector<long long> minimum_distance_for_year(n, INFTY);
  minimum_distance_for_year[n - 1] = total_distance[n - 1];
  // Bottom up DP. Loop over years.
  for (int i = n - 2; i >= 0; --i) {
    minimum_distance_for_year[i] = min(minimum_distance_for_year[i + 1],
                                       total_distance[i]);
  }

  // Print solution.
  for (int i = 0; i < n; ++i) {
    cout << setprecision(18) << 1e15 - minimum_distance_for_year[i] << endl;
  }
}


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

int main(){
  int N; //支払額
  int A; //1円の枚数
  int Ns;
  cin >> N;
  cin >> A;
  
  Ns = N / 500;     
  if(N-Ns*500 <= A){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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




int main() 
{ 
    ios::sync_with_stdio(false);
    cin.tie(0);
    
   int n; cin>>n;
   int a = 0, b=0;
   
   while(n--){
      string x, y; 
      cin>>x>>y;
      if(x<y) b += 3;
      else if(x>y) a += 3;
      else{
          a++;
          b++;
      }
        
   }
   cout<<a<<" "<<b<<endl;
	return 0; 
} 



Measured memory_bytes: 3232
n = int(input())
import math
from bisect import bisect
ps = {}
for i in range(2,math.ceil(math.sqrt(n))):
  while n % i == 0:
    n //= i
    if i in ps:
      ps[i] += 1
    else:
      ps[i] = 1
  if n == 1:
    break
if n > 1:
  ps[n] = 1

ss = [i*(i+1)//2 for i in range(1,42)]

ans = 0
for p in ps:
  ans += bisect(ss, ps[p])
print(ans)

Measured memory_bytes: 9156
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int x;
    cin>>x;
    
    if(x<1200){
        cout<<"ABC"<<endl;
    }else{
        cout<<"ARC"<<endl;
    }
    
    
    
    
    
    return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
    long long n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    long long l, a, x, y;
    a = gcd(n, m);
    l = (n * m) / a;
    x = n / a;
    y = m / a;
    bool ans = 1;
    for (long long i = 0; i < a; i++) {
        long long c = x * i, d = y * i;
        if (s[c] != t[d]) ans = 0;
    }
    if (ans == 1)
        cout << l << endl;
    else
        cout << "-1" << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)

int main(){
	int n,a = 0,b = 0;
	string s,ans;
	cin >> n >> s;
	REP(i, n) {
		if (s[i] == '(')a++;
		else {
			if (a > 0)a--;
			else b++;
		}
	}
	REP(i, b)ans.push_back('(');
	ans = ans + s;
	REP(i, a)ans.push_back(')');
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int n=s.nextInt();
		int m=s.nextInt();
		
		long t=s.nextLong();
		
		long[] arr=new long[n];
		
		for(int i=0;i<n;i++)
		{
			arr[i]=s.nextInt();
		}
		
		long[] brr=new long[m];
		
		for(int i=0;i<m;i++)
		{
			brr[i]=s.nextInt();
		}
		
		long[] sum1=new long[n];
		long[] sum2=new long[m];
		
		sum1[0]=arr[0];
		
		for(int i=1;i<n;i++)
		{
			sum1[i]=sum1[i-1]+arr[i];
		}
		
		sum2[0]=brr[0];
		
		for(int i=1;i<m;i++)
		{
			sum2[i]=sum2[i-1]+brr[i];
		}
		
		long max=find(t,sum2);
		
		for(int i=0;i<n;i++)
		{
			long count=0;
			
			if(t-sum1[i]>=0)
			{
				count=i+1;
				
				count=count+find(t-sum1[i],sum2);
				
				if(count>max)
					max=count;
			}
		}
		
		System.out.println(max);
		
	}
	
	public static long find(long t,long[] sum2)
	{
		int start=0;
		int end=sum2.length-1;
		
		int ans=0;
		
		while(start<=end)
		{
			int mid=(start+end)/2;
			
			if(sum2[mid]<=t)
			{
				ans=mid+1;
				start=mid+1;
			}
			else
			{
				end=mid-1;
			}
		}
		
		return ans;
	}
	
}

Measured memory_bytes: 63060
import fractions
import math
a, b = map(int, input().split())
greatest = fractions.gcd(a, b)

factor = [1]
max_iter = int(math.sqrt(greatest)) + 1
for i in range(2, max_iter):
    while greatest % i == 0:
        greatest //= i
        factor.append(i)
if greatest != 1:
    factor.append(greatest)
factor = set(factor)
print(len(factor))


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

int main()
{
    int n;
    while(cin>>n , n){
        
        for(int i=0; i<n; i++){
            int x1,y1,z1,w1,x2,y2,z2,w2,x3,y3,z3,w3;
            cin>>x1>>y1>>z1>>w1>>x2>>y2>>z2>>w2;
        
            x3 = x1*x2 + (-1*y1*y2) + (-1*z1*z2) + (-1*w1*w2);
            y3 = x1*y2 + y1*x2 + z1*w2 + (-1*w1*z2);
            z3 = x1*z2 + (-1*y1*w2) + z1*x2 + w1*y2;
            w3 = x1*w2 + y1*z2 + (-1*z1*y2) + (w1*x2);
        
            cout<<x3<<" "<<y3<<" "<<z3<<" "<<w3<<endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <string.h>
int main(void){
    int ans=0 ;
    char s[30] ;
    scanf("%s",s) ;
    for (int i=0; i<strlen(s); i++) {
        for (int j=i+1; j<strlen(s); j++) {
            if (s[i]==s[j]) {
                ans++ ;
            }
        }
    }
    if (ans==0) {
        printf ("yes\n") ;
    } else {
        printf ("no\n") ;
    }
    return 0 ;
}

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

#define ll int
#define nl endl
#define pi 3.14159265358979323846
#define ff first 
#define ss second
#define pb push_back
#define watch(xxx) cerr<<(#xxx)<<" is "<<xxx<<nl;
const int mod=1e9+7;

int main(){

ll t=1; 
//~ scanf("%d",&t);

while(t--){
	 ll x1,x2,x3,x4,x5; cin>>x1>>x2>>x3>>x4>>x5;
 if(x1==0)cout<<1<<endl;
	 if(x2==0)cout<<2<<endl;
	 if(x3==0)cout<<3<<endl;
	 if(x4==0)cout<<4<<endl;
	 if(x5==0)cout<<5<<endl;
	 
}
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main ()
{
    int W, H, x, y, r;

    cin >> W >> H >> x >> y >> r;

    if ( (x - r) < 0 || W < (x + r) || (y - r) < 0 || H < (y + r) ) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <functional>
#include <map>
#include <math.h>
#include <list>

using namespace std;

#define ll long long int

int gcd(int m, int n)
{
	// 引数に０がある場合は０を返す
	if ((0 == m) || (0 == n))
		return 0;

	while (m != n)
	{
		if (m > n) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd

int main(void) {

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


	ll k;
	ll sum = 0;
	cin >> k;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int h = 1; h <= k; h++) {

				sum += gcd(gcd(i, j), gcd(j, h));


			}
		}
	}
	cout << sum << endl;




	return 0;
}


Measured memory_bytes: 3564
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main(){ 
int a, b=0,c;
    cin>>a;
    if(a<4){
        cout<<1;
        return 0;
    }
    for(int i=2;i<33;i++){
        for(int o=2;o<33;o++){
                      c=pow(o,i);
            if(c<=a) b=max(b,c);
            else break;
        }
    }
    cout<<b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
 
int main() {
    fast();
    /*ll t;
    cin>>t;
    while(t--)
    {
       
    }*/
    ll n;
    cin>>n;
    ll h[n];
    ll dp[n];
    for(ll i=0;i<n;i++)
    cin>>h[i];
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    for(ll i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
s = list(input())
i=0
li = [0]
num = 0
while i<=len(s)-1:
    
    s1 = ["A","C","G","T"]
    
    if s[i] in s1 :
        num += 1
        i += 1
        li.append(num)
    elif s[i] not in s1 :
        num = 0
        i += 1
        
print(max(li))

Measured memory_bytes: 3060
/**
 *		author:  zvm
 *		created: 28.09.2020 16:57:05
**/

#include <bits/stdc++.h>

using namespace std ;

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

	int n, a, b ;
	cin >> n >> a >> b ;

	auto digit_sum = [&]( int x ) {
		int sum = 0 ;
		for( ; x ; x/=10 ) {
			sum += x%10 ;
		}
		return sum ;
	};
	
	int ans = 0 ;
	for( int i = 1 ; i <= n ; ++i ) {
		int sum = (digit_sum(i)) ;
		if( a <= sum && sum <= b ) {
			ans += i ;
		}
	}

	cout << ans << endl ;
}


Measured memory_bytes: 3604
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 
mod = 10**9+7  
nums = 10**6 # 制約に合わせよう
g1, g2, inverse = [1, 1] , [1, 1], [0, 1]
 
for num in range(2, nums + 1):
    g1.append((g1[-1] * num) % mod)
    inverse.append((-inverse[mod % num] * (mod//num)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)
    
x, y = map(int, input().split())
if (x+y)%3 or 2*x<y or 2*y<x:
    print(0)
else:
    print(cmb((x+y)//3,(2*x-y)//3, mod))

Measured memory_bytes: 127572
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int a, b;
    cin >> a >> b;
    string as = to_string(a), bs = to_string(b);
    rep(i, b-1) as += to_string(a);
    rep(i, a-1) bs += to_string(b);
    if (as < bs) cout << as << endl;
    else cout << bs << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define F(i,a,b) for(int i= (int)(a); i<(int)(b);i++)
#define FI(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define what_is(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define vii vector<int,int>
#define pb push_back
#define endl '\n'
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
const int N = 1e6+7 ;
string s ;
const int INF = 1e9+7 ;

int main(){fast ;
	int n,k ;
	cin >> n >> k ;
	vector<int>x(n) ;
	for(int &i : x)
	    cin >> i ;
	vector<int>dp(n, INF) ;
	dp[0] = 0 ;
	F(i,0,n){
		for(int j = i+1 ;j <= i+k && j < n ; j++){
			dp[j] = min(dp[j],dp[i]+ abs(x[i] - x[j])) ;
		}
			
	}
	
	cout << dp[n-1] << endl ;
	



}




Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int a,b,c,d,x;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	x=0;
	if(a<=b){
		x=x+a;
	}
	else if(b<=a){
		x=x+b;
	}
	if(c<=d){
		printf("%d\n",x=x+c);
	}
	else if(d<=c){
		printf("%d\n",x=x+d);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#define mp make_pair
#define fi first
#define se second
using namespace std;

typedef pair <int, int> pii;

const int MAXN = 1e5 + 1;

int n, m;
pii q[MAXN];
int l, r;
int sol;

int main(){

    cin >> n >> m;
    for (int i = 0; i < m; i++){
        cin >> q[i].fi >> q[i].se;
        if (q[i].fi > q[i].se) swap(q[i].fi, q[i].se);
    }

    sort(q, q+m);

    l = 1;
    r = n-1;
    sol = 1;

    for (int i = 0; i < m; i++){

        //cout << q[i].fi << " " << q[i].se << "   -   " << l << r << '\n';
        if (q[i].fi > r || q[i].se <= l){
            //cout << "here\n";
            sol++;
            l = 1;
            r = n-1;
        }

        l = max(l, q[i].fi);
        r = min(r, q[i].se-1);

    }

    cout << sol;

}

Measured memory_bytes: 1024
import heapq

n=int(input())
a1=[]
b1=[]
a2=[]
b2=[]
s=input().split()
for i in range(3*n):
    if i<n:
        a1.append(int(s[i]))
    elif i>=2*n:
        b1.append(-int(s[i]))
    else:
        a2.append(int(s[i]))
        b2.append(-int(s[3*n-i-1]))
suma=[sum(a1)]
sumb=[sum(b1)]
heapq.heapify(a1)
heapq.heapify(b1)

for i in range(0,n):
    heapq.heappush(a1,a2[i])
    k=heapq.heappop(a1)
    l=suma[-1]
    suma.append(l+a2[i]-k)
for i in range(0,n):
    heapq.heappush(b1,b2[i])
    k=heapq.heappop(b1)
    l=sumb[-1]
    sumb.append(l+b2[i]-k)

ma=-1000000000000000
for i in range(n+1):
    ma=max(ma,suma[i]+sumb[-i-1])
print(ma)


Measured memory_bytes: 49148
from collections import defaultdict

N, M = map(int, input().split())
aList = [int(input()) for _ in range(M)]
mod = 1000000007

dp = defaultdict(int)
dp[0] = 1
for i, a in enumerate(aList):
    dp[a] = None

for i in range(1, N + 1):
    if dp[i] != None:
        if i >= 1 and dp[i - 1] != None:
            dp[i] += dp[i - 1]
        if i >= 2 and dp[i - 2] != None:
            dp[i] += dp[i - 2]

        dp[i] %= mod

if dp[N] == None:
    dp[N] = 0
print(dp[N])


Measured memory_bytes: 59736
def Main(N, M, S, C):
    d = {1:set([]), 2:set([]), 3:set([])}
    for i in range(M):
        d[S[i]].add(C[i])
    for v in d.values():
        if len(v) >= 2:
            return -1
    if N == 3:
        d1 = d2 = d3 = 0
        if len(d[1]) == 0:
            d1 = 1
        else:
            d1 = d[1].pop()
            if d1 == 0:
                return -1
        if len(d[2]) == 0:
            d2 = 0
        else:
            d2 = d[2].pop()
        if len(d[3]) == 0:
            d3 = 0
        else:
            d3 = d[3].pop()
        return d1*100+d2*10+d3
    elif N == 2:
        d1 = d2 = 0
        if len(d[1]) == 0:
            d1 = 1
        else:
            d1 = d[1].pop()
            if d1 == 0:
                return -1
        if len(d[2]) == 0:
            d2 = 0
        else:
            d2 = d[2].pop()
        return d1*10+d2
    else:
        return d[1].pop()
            
            
    
                

def main():
    N, M = map(int, input().split())
    if M == 0:
        if N == 3:
            print(100)
        if N == 2:
            print(10)
        if N == 1:
            print(0)
        return
    S = [0]*M
    C = [0]*M
    for i in range(M):
        S[i], C[i] = map(int, input().split())
    print(Main(N, M, S, C))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
def main():
  N = int(input())
  A = list(map(int,input().split()))
  B = list(map(int,input().split()))

  cnt = 0
  for i in range(N):
    if B[i] - A[i] >= 0:
      cnt += A[i]
      B[i] -= A[i]
      A[i] = 0
    elif B[i] - A[i] < 0:
      cnt += B[i]
      tmp = B[i]
      B[i] = 0
      A[i] -= tmp
    if B[i] == 0:
      continue
    if B[i] - A[i+1] >= 0:
      cnt += A[i+1]
      B[i] -= A[i+1]
      A[i+1] = 0
    elif B[i] < A[i+1]:
      cnt += B[i]
      tmp = B[i]
      B[i] = 0
      A[i+1] -= tmp
  print(cnt)

if __name__ == "__main__":
  main()

Measured memory_bytes: 19000
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] copy = new int[s.Length];
            Array.Copy(s, copy,n);
            Array.Sort(copy);
            int left = copy[(n / 2)-1];
            int right = copy[(n / 2)];

            for (int i = 0; i < n; i++)
            {
                if (s[i] <= left)
                {
                    WriteLine(right);
                }
                else
                {
                    WriteLine(left);
                }
            }
        }
    }
}

Measured memory_bytes: 34120
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
template<class T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
 /* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)*/
template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////

int main() {
ll ans = 0;
	int N; cin >> N;
	ll X; cin >> X;
	vector<ll> A;

	rep(i,N)
	{
		ll a; cin >> a;
		A.PB(abs(a-X));
	}
	
	ll a = A.at(0);
	rep(i,N-1)
	{
		ll b; b = A.at(i+1);
		a = gcd(a,b);
	}
	ans = a;
	cout << ans << endl;

}

Measured memory_bytes: 1400
from collections import Counter
from functools import reduce
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # greatest common divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # least common multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


n = II()
happiness = [LI() for _ in range(n)]
dp = [[0 for i in range(3)] for i in range(n+1)]
for i in range(n):
    dp[i+1][0] = max(dp[i][1]+happiness[i][0], dp[i][2]+happiness[i][0])
    dp[i+1][1] = max(dp[i][0]+happiness[i][1], dp[i][2]+happiness[i][1])
    dp[i+1][2] = max(dp[i][0]+happiness[i][2], dp[i][1]+happiness[i][2])
P(max(dp[-1]))



Measured memory_bytes: 47640
import re
n = int(input())
R = []
for i in range(n):
    S, P = input().split()
    R.append((S, int(P),int(i+1)))

Point = []
for j in range(n):
    Point.append(R[j][0])
Point = list(sorted(set(Point)))
Point
SR = sorted(R, key=lambda x:(x[0], -int(x[1])))
for k in range(n):
    print(SR[k][2])
pass

Measured memory_bytes: 9832
n, l = list(map(int, input().split()))

taste_list = []

for i in range(1, n+1):
    taste = l + i - 1
    taste_list.append(taste)

abs_taste_list = [abs(x) for x in taste_list]
target_index = abs_taste_list.index(min(abs_taste_list))
taste_list.remove(taste_list[target_index])
ans = sum(taste_list)
print(ans)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String input = sc.next();
		int tmp = sc.nextInt();
		//Long tmp = sc.nextLong();
      	
      if(tmp % 7 == 0 || tmp % 4 == 0){
        System.out.println("Yes");
        return;
      }else if(tmp <= 3){
        System.out.println("No");
      return;
      }
      
      int fourOnly = tmp;
      while(fourOnly > 0){
        fourOnly = fourOnly - 4;
          if(fourOnly % 7 == 0){
            System.out.println("Yes");
            return;
          }
        }
      
      int fourSeven = tmp;      
      while(fourSeven > 0){
          if(fourSeven % 4 == 0){
            System.out.println("Yes");
            return;
          }
        fourSeven = fourSeven - 7;
        }
      System.out.println("No");
      return;
	}
}


Measured memory_bytes: 22740
#include <iostream>
using namespace std;
int main(void){
    int n,m;
    char a[51][51],b[51][51];
    
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            cin>>b[i][j];
        }
    }
    for(int i=0;i<=n-m;i++){
        for(int j=0;j<=n-m;j++){
            int  s=1;
            for(int k=0;k<m&&s;k++){
                for(int l=0;l<m&&s;l++){
                    if(a[i+k][j+l]!=b[k][l])s=0;
                }
            }
            if(s==1){
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,x,y,mn;
int main()
{
	scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&x,&y);
	mn=min(a+b,2*c);
	if(y>x)
	{
		printf("%lld\n",(y-x)*min(b,2*c)+mn*x);
	}else
	{
		printf("%lld\n",(x-y)*min(a,2*c)+mn*y);
	}
}

Measured memory_bytes: 3836
inputs = Array.new
while line = $stdin.gets
  inputs << line.chomp
end

N = inputs[0]
As = inputs[1].split(" ").map(&:to_i)

cnt = 0
As.each do |a|
  cnt += 1 if a < 0
end

# 偶数個の場合は全てを>0にできる
# 奇数個の場合は一つの数をのぞいて>0にできる
bs = As.map{|a| a > 0 ? a : - a}

res = bs.reduce(:+)
if cnt % 2 == 1
  # 奇数の場合は最小の数を除く
  res = res - bs.min * 2
end

puts res


Measured memory_bytes: 9512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int ans = 0;
    rep(i,n) {
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	long long n, p;
	cin >> n >> p;
	long long ans = 1;
	map<long long, long long> mp;
	for(long long i = 2; i * i <= p; i++) {
		while(p % i == 0) {
			mp[i]++;
			p /= i;
		}
	}
	if(p != 1) {
		mp[p]++;
	}
	for(auto i : mp) {
		if(i.second >= n) {
			ans *= pow(i.first, i.second / n);
		}
	}
	cout << ans << endl;
	
	return 0;	
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int ans = 0;
    for(int i=0; i<n; i++){
        if(i%2==0) ans += a[i];
        else ans -= a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
char s[4005];
ll ans;
int main(){
	int n,a[3]={};
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++){
		if(s[i]=='R') a[0]++;
		else if(s[i]=='G') a[1]++;
		else a[2]++;
	} 
	ans=(ll)a[0]*a[1]*a[2];
	for(int i=1;i<n;i++)
		for(int d=1;i+d+d<=n;d++)
			if((s[i]^s[i+d]^s[i+d+d])==('R'^'G'^'B')) --ans;
	printf("%lld\n",ans);
	return 0;
}

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

void dfs(int cw, int remain)
{
  if (!cw || !remain)
    return;

  if (remain >= cw) {
    dfs(cw/2, remain-cw);
    if (remain != cw)
      cout << " ";
    cout << cw;
  } else {
    dfs(cw/2, remain);
  }
}

int main(int argc, char **argv)
{
  int x;

  for (;;) {
    cin >> x;
    if (cin.eof())
      break;
    dfs(512, x);
    cout << endl;
  }
  return 0;
}

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


int n;
vector<vector<long long int>> adj;
long long int mod=1000000007;


vector<vector<long long int>> mul(vector<vector<long long int>> a,vector<vector<long long int>> b){
	vector<vector<long long int>> ans;
	for(int i=0;i<n;i++){
		vector<long long int> t;
		for(int j=0;j<n;j++){
			long long int s=0;
			for(int k=0;k<n;k++){
				s = (s+a[i][k]*b[k][j])%mod;
			}
			t.push_back(s);
		}
		ans.push_back(t);
	}
	return ans;
}

vector<vector<long long int>> poww(long long int k){
	vector<vector<long long int>> ans;
	if(k==0){
		for(int i=1;i<=n;i++){
			vector<long long int> t;
			for(int j=1;j<=n;j++){
				if(i==j) t.push_back(1);
				else t.push_back(0);
			}
			ans.push_back(t);
		}
		return ans;
	}
	ans = poww(k/2);
	ans = mul(ans,ans);
	if(k%2) return mul(ans,adj);
	return ans;
}



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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif

	long long int k;
	cin >> n >> k;
	for(int i=1;i<=n;i++){
		vector<long long int> v(n);
		for(int j=1;j<=n;j++){
			cin >> v[j-1];
		}
		adj.push_back(v);
	}

	vector<vector<long long int>> tt = poww(k);
	
	long long int ans=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			ans=(ans+tt[i][j])%mod;
		}
	}
	cout << ans;
	


	
	




	
	




	

}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int n;
int h[105];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> h[i];
	
	int ans = 0;
	for(int i = 1; i <= 100; i++){
		for(int j = 1; j <= n+1; j++){
			if(h[j-1] >= i && h[j] < i) ans++;
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int a, b, c; cin >> a >> b >> c;
    if (a == b && b == c) cout << 1 << endl;
    else if (a == b || b == c || c == a) cout << 2 << endl;
    else cout << 3 << endl;
    return 0;
}


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

#define INF 0x7fffffff

int main() {
	int		a,b,c,i,j,k,n,m,x,y,ans = 0;
	int		tmp = INF;
	string	str;
	
	cin >> n;
	
	
	double aaa = n;
	aaa = aaa / 3;
	
	printf("%f\n",aaa*aaa*aaa);

}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iso646.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main()
{
    ll n;
    cin >> n;
    vll a(n);
    for (auto &e : a)
        cin >>
            e;
    ll m = 0;
    ll i;
    for (i = 0; i < n; i++)
    {
        m = max(m, a[i]);
    }
    ll d = m;
    ll mid1, mid2;
    if (m % 2 == 0)
    {
        mid1 = m / 2;
        mid2 = m / 2;
    }
    else
    {
        mid1 = m / 2;
        mid2 = mid1 + 1;
    }
    ll a2 = m;
    for (i = 0; i < n; i++)
    {
        if (a[i] == m)
            continue;
        if (a[i] <= mid1)
        {
            ll e = mid1 - a[i];
            if (e < d)
            {
                d = e;
                a2 = a[i];
            }
        }
        else
        {
            ll e = a[i] - mid2;
            if (e < d)
            {
                d = e;
                a2 = a[i];
            }
        }
    }
    cout << m << " " << a2 << endl;
    return 0;
}


Measured memory_bytes: 1656
from collections import deque
N,M = map(int,input().split())
ans = [-1]*(N+1)
E = [[] for i in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    E[a].append(b)
    E[b].append(a)

q = deque([1])
while(q):
    v = q.popleft()
    for s in E[v]:
        if(ans[s] == -1):
            ans[s] = v
            q.append(s)
    
for s in ans[2:]:
    if(s == -1):
        print("No")
        exit()
print("Yes")
for s in ans[2:]:
    print(s)

Measured memory_bytes: 35004
#include <iostream>
#include <string>
#include <vector>

#include <math.h>

using namespace std;

static inline bool judge_prime(const int num) {
	if (num < 2) {
		return false;
	}
	else if (num == 2) {
		return true;
	}
	else if (num % 2 == 0) {
		return false;
	}
	else if (num == 3) {
		return true;
	}

	if (num % 3 == 0) {
		return false;
	}

	if(num % 6 != 1 && num % 6 != 5) {
		return false;
	}

	const double sqrtnum = sqrt(num);
	for(int i = 5; i <= sqrtnum; i += 6) {
		if(num % i == 0) {
			return false;
		}
		if (num % (i + 2) == 0) {
			return false;
		}
	}
	return true;
}

static int count_prime(const int input) {
	int counter_prime = 0;

	for (int i = input; 1 < i; i --) {
		if (judge_prime(i)) {
			counter_prime ++;
		}
	}
	return counter_prime;
}

int main() {
	int input;
	while(cin >> input) {
		cout << count_prime(input) << endl;
	}
	return 0;
}



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

#define EPS 1e-10

int rel_s_s( double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double *x, double *y ) {
	double numer = ( x3 - x1 ) * ( y4 - y3 ) - ( x4 - x3 ) * ( y3 - y1 );
	double denom = ( x2 - x1 ) * ( y4 - y3 ) - ( x4 - x3 ) * ( y2 - y1 );

	if ( fabs( denom ) < EPS )
		if ( fabs( numer ) < EPS ) {
			double h1, h2;

			if ( x1 == x2 ) {
				h1 = ( y3 - y1 ) / ( y2 - y1 );
				h2 = ( y4 - y1 ) / ( y2 - y1 );
			} else {
				h1 = ( x3 - x1 ) / ( x2 - x1 );
				h2 = ( x4 - x1 ) / ( x2 - x1 );
			}

			if ( ( h1 < h2 ? h1 : h2 ) < 0.0 && fabs( h1 < h2 ? h2 : h1 ) < EPS ) {
				*x = x1;
				*y = y1;
				return 4;
			} else if ( fabs( ( h1 < h2 ? h1 : h2 ) - 1.0 ) < EPS && 1.0 < ( h1 < h2 ? h2 : h1 ) ) {
				*x = x2;
				*y = y2;
				return 4;
			} else if ( h1 < 0.0 && h2 < 0.0 || 1.0 < h1 && 1.0 < h2 )
				return 3;
			else
				return 5;
		} else
			return 2;
	else {
		double t = numer / denom;
		double s = ( ( x3 - x1 ) * ( y2 - y1 ) - ( x2 - x1 ) * ( y3 - y1 ) ) / denom;

		if ( fabs( t - 0.5 ) < 0.5 + EPS && fabs( s - 0.5 ) < 0.5 + EPS ) {
			*x = x1 + t * ( x2 - x1 );
			*y = y1 + t * ( y2 - y1 );

			if ( fabs( ( x2 - x1 ) * ( x4 - x3 ) + ( y2 - y1 ) * ( y4 - y3 ) ) < EPS )
				return 1;
			else
				return 0;
		} else
			return 6;
	}
}

int main( void ) {
	int q;

	scanf( "%d", &q );
	while ( q-- ) {
		int rel;
		double x0, y0, x1, y1, x2, y2, x3, y3, x, y;

		scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3 );

		rel = rel_s_s( x0, y0, x1, y1, x2, y2, x3, y3, &x, &y );
		printf( "%d\n", rel == 2 || rel == 3 || rel == 6 ? 0 : 1 );
	}

	return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long t1 = sc.nextLong();
    long t2 = sc.nextLong();
    long a1 = sc.nextLong();
    long a2 = sc.nextLong();
    long b1 = sc.nextLong();
    long b2 = sc.nextLong();
    if(a1*t1+a2*t2==b1*t1+b2*t2)System.out.println("infinity");
    else if((a1>b1&&a2>b2)||(a1<b1&&a2<b2))System.out.println(0);
    else if(a1>=b1&&a2<=b2){
      long d = (a2-b2)*t2+(a1-b1)*t1;
      if(d>0)System.out.println(0);
      else if(d<0){
        if((b1*t1-a1*t1)%d!=0)System.out.println(((b1*t1-a1*t1)/d)*2+1);
        else System.out.println(((b1*t1-a1*t1)/d)*2);
      }
    }
    else if(a1<=b1&&a2>=b2){
      long d = (b2-a2)*t2+(b1-a1)*t1;
      if(d>0)System.out.println(0);
      else if(d<0){
        if((a1*t1-b1*t1)%d!=0)System.out.println(((a1*t1-b1*t1)/d)*2+1);
        else System.out.println(((a1*t1-b1*t1)/d)*2);
      }
    }
  }
}

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

int main()
{
	long long N,A[30],B[30],C[30],i,j,m;
	while(cin>>N)
	{
		for(i=0;i<N;i++)
		{
			cin>>A[i];
		}
		for(i=0;i<N;i++)
		{
			cin>>B[i];
		}
		for(i=0;i<N-1;i++)
		{
			cin>>C[i];
			C[N-1]=0;
		}
		for(i=0,m=0;i<N;i++)
		{
			if((A[i]-A[i-1])==1&&A[i]!=1){
				m=m+B[A[i]-1]+C[A[i]-2];
			}
			else{
				m=m+B[A[i]-1];
			}
		}
		cout<<m<<endl;
	}
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect
def sieve_of_eratosthenes_2017(N):
    numbers = [n & 1 for n in range(N + 1)]
    numbers[1] = 0
    numbers[2] = 1
    like2017 = []
    p = 1
    while True:
        while not numbers[p]:
            p += 2
        if p * p > N:
            for i in range(p, N + 1, 2):
                if numbers[i] & numbers[(i + 1) >> 1]:
                    like2017.append(i)
            return like2017
        if numbers[(p + 1) >> 1]:
            like2017.append(p)
        for i in range(p * 2, N + 1, p):
            numbers[i] = 0
        p += 2

like2017 = sieve_of_eratosthenes_2017(10 ** 5)
Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    lindex = bisect_left(like2017, l)
    rindex = bisect(like2017, r)
    print(rindex - lindex)

Measured memory_bytes: 56992
import math

a,b,C = list(map(float,input().split()))
C = math.radians(C)  # radに変換
h = math.sin(C) * b  # 高さを出す
remain = math.sqrt(a ** 2 + b ** 2 - (2 * a * b * math.cos(C)))
S = (a * h)/ 2  # 面積
print(S)
print(a+b+remain)
print(h)


Measured memory_bytes: 5688
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<ll > vecll;
typedef vector<vector<int > > vec2int;
typedef vector<bool > vecbool;
typedef vector<string > vecstr;
////////////////////////////////////////////////
int main()
{
  int n; cin >> n;
  vecll t(n), a(n);
  ll nt = 1;
  ll na = 1;
  REP(i,n){
    cin >> t[i] >> a[i];
    ll k = max((nt + t[i] - 1)/t[i],(na + a[i] - 1)/a[i]);
    nt = k*t[i];
    na = k*a[i];
  }
  cout << nt + na << endl;
}


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

int main(){
    int N, M;
    int A[10000];

    int work_day = 0;

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

    if(work_day > N) cout << "-1" << endl;
    else cout << N-work_day << endl;

    return 0;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
#define N 1000000007 // prime modulo value 

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAXN]; ll visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

// <------------- Declare Variables Here ------------> //

ll t = 1;
ll n, k;
string s;

// <------------- Implement Functions Here ----------> //


long long exponentiation(long long base,
                         long long exp)
{
	if (exp == 0)
		return 1;

	if (exp == 1)
		return base % N;

	long long t = exponentiation(base, exp / 2);
	t = (t * t) % N;

	// if exponent is even value
	if (exp % 2 == 0)
		return t;

	// if exponent is odd value
	else
		return ((base % N) * t) % N;
}

// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n >> k;
	ll ans = 0;
	ll cnt[k+5];
	mset(cnt,0);
	for (ll i = k; i > 0; i--) {
		cnt[i] = exponentiation(k / i, n);
		for (ll j = 2 * i; j <= k; j += i) {
			cnt[i] = (cnt[i] - cnt[j] + MOD) % MOD;
		}
		ans = (ans + i*cnt[i])%MOD;
	}
	cout<<ans;newl;
}

int main() {
	fastio; randomINT;
	//cin>>t;
	while (t--) {
		MAIN();
	}
	return 0;
}


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

int N, M;

int main() {
    while (cin >> N >> M, (N||M)) {
        vector<int> n(N), m(M);
        int nsum = 0, msum = 0;
        pair<int, int> ans = {-101, -101};
        rep(i, N) { cin >> n[i]; nsum += n[i]; }
        rep(i, M) { cin >> m[i]; msum += m[i]; }
        rep(i, N) {
            int nt = nsum-n[i];
            rep(j, M) {
                int mt = msum+n[i];
                if (nt+m[j] == mt-m[j]) {
                    int pt = n[i]+m[j];
                    if (ans.first+ans.second == -101*2) ans = {n[i], m[j]};
                    else ans = ((pt < ans.first+ans.second) ? make_pair(n[i], m[j]) : ans);
                }
            }
        }
        if (ans.first+ans.second == -101*2) cout << -1 << endl;
        else cout << ans.first << " " << ans.second << endl;
    }
}

Measured memory_bytes: 2992
import java.util.Collections;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			final int r = sc.nextInt();
			
			if(n == 0 && r == 0){
				break;
			}
			
			LinkedList<Integer> list = new LinkedList<Integer>();
			for(int i = 0; i < n; i++){
				list.add(i+1);
			}
			Collections.reverse(list);
			
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			for(int i = 0; i < r; i++){
				
				int p = sc.nextInt();
				int c = sc.nextInt();
				
				tmp.clear();
				
				for(ListIterator<Integer> ite = list.listIterator(p-1); c > 0 ;c--){
					int num = ite.next();
					ite.remove();
					tmp.add(num);
				}
				
				Collections.reverse(tmp);
				
				for(int t : tmp){
					list.addFirst(t);
				}
				
				
			}
			
			System.out.println(list.peek());
			
			
		}
		
	}

}

Measured memory_bytes: 13000
#include <iostream>
#include <stdlib.h>
#include <string>
#define llint long long
#define mod 1000000007

using namespace std;

string s;
llint dp[100005][2];

int main(void)
{	
	cin >> s;
	int n = s.size();
	s = "#" + s;
	
	dp[0][0] = 1;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 2; j++){
			
			for(int k = 0; k < 2; k++){
				for(int l = 0; l < 2; l++){
					if(k == 1 && l == 1) continue;
					int x = k+l;
					if(j == 0 && s[i+1] == '0' && x == 1) continue;
					int nj = j;
					if(s[i+1] == '1' && x == 0) nj = 1;
					
					dp[i+1][nj] += dp[i][j], dp[i+1][nj] %= mod;
				}
			}
			
		}
	}
	llint ans = dp[n][0] + dp[n][1];
	cout << ans % mod << endl;
	
	return 0;
}

Measured memory_bytes: 2044
def main():
    import sys
    input = sys.stdin.readline
    N, K = [int(x) for x in input().strip().split()]
    A = [int(x) for x in input().strip().split()]
    l = [0] * (N + 1)
    for i, a in enumerate(A):
        l[max(0, i-a)] += 1
        l[min(N, i+a+1)] -= 1
    p = 0
    cumsum = [0] * (N + 1)
    for i in range(N+1):
        p += l[i]
        cumsum[i] = p
    cumsum_ = A + [0]
    for k in range(min(K-1, 50)):
        p = 0
        for i in range(N+1):
            l[max(0, i-cumsum[i])] += 1
            l[min(N, i+cumsum[i]+1)] -= 1
            l[max(0, i-cumsum_[i])] -= 1
            l[min(N, i+cumsum_[i]+1)] += 1

        cumsum_ = cumsum[:]
        for i in range(N+1):
            p += l[i]
            cumsum[i] = p

    print(*cumsum[:-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 199728
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
int n, A[N], root;
vector<int>V[N];
using ll = long long;

void Dfs (int u, int fa) {
	if (V[u].size() == 1) return ;
	ll S = -A[u], D = 0;
	for (auto v : V[u]) if (v != fa) {
		Dfs(v, u);
		S += A[v];
		if (A[v] > D) D = A[v];
	}
	if (S < 0) puts("NO"), exit(0);
	if (A[u] < D) puts("NO"), exit(0);
	A[u] -= S;
	if (A[u] < 0) puts("NO"), exit(0);
}

int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &A[i]);
	if (n == 2) return puts(A[1] == 1 && A[2] == 1 ? "YES" : "NO"), 0;
	for (int i = 1, u, v; i < n; ++i) scanf("%d%d", &u, &v), V[u].emplace_back(v), V[v].emplace_back(u);
	for (int i = 1; i <= n; ++i) if (V[i].size() > 1) { root = i; break; }
	Dfs(root, 0);
	puts(A[root] ? "NO" : "YES");
	return 0;
}

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

namespace ABC113A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] c = Console.ReadLine().Split();
            int A = int.Parse(c[0]);
            int B = int.Parse(c[1]);
            int s;
            s = A + B / 2;
            Console.Write(s);
        }
    }
}


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

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int k, x;
  cin >> k >> x;
  for (int i = x - k + 1; i < x + k; i++) {
    cout << i << ' ';
  }
  return 0;
}

Measured memory_bytes: 256
while(s=gets.gsub(/\d+/){|k|?1*k.to_i})!~/#/
n=1+s.index(?/)
eval"s[n*x-n+y-1]=?1;s[n*z-n+w-1]=?b!&%".tr('x!y&z%w',gets)
$><<s.gsub(/1+/,&:size)
end

Measured memory_bytes: 8828