akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
int n,D1,D2,N,x[360001],y[360001],c[2][360001];
std::vector<int>vec[4];
void getcol(int D,int*c){
	int A=1;
	while(D%4==0)D>>=2,A<<=1;
	for(int i=1;i<=N;++i)
		if(D%4==1)c[i]=((x[i]/A)+(y[i]/A))&1;
		else c[i]=(x[i]/A)&1;
}
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	n=gi(),D1=gi(),D2=gi(),N=n*n*4;
	for(int i=1;i<=N;++i)x[i]=(i-1)/(2*n),y[i]=(i-1)%(2*n);
	getcol(D1,c[0]),getcol(D2,c[1]);
	for(int i=1;i<=N;++i)vec[(c[0][i]<<1)|c[1][i]].push_back(i);
	for(int i=0;i<4;++i)
		if(vec[i].size()>=n*n){
			N=n*n;
			for(int j:vec[i]){
				printf("%d %d\n",x[j],y[j]);
				if(!--N)break;
			}
			exit(0);
		}
	return 0;
}


Measured memory_bytes: 8504
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int n, m; cin >> n >> m;
  vector<int> a(n); REP(i, n) cin >> a[i];
  map<int, int> mp;
  vector<long long> sum(n);
  sum[0] = a[0] % m;
  FOR(i, 1, n) sum[i] = (sum[i - 1] + (a[i] % m)) % m;
  REP(i, n) ++mp[sum[i]];
  long long ans = 0, now = 0;
  REP(i, n) {
    ans += mp[now];
    (now += a[i] % m) %= m;
    --mp[sum[i]];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4352
//
//  main.cpp
//  Competitive
//
//  Created by Ashutosh Tiwari on 16/05/20.
//  Copyright © 2020 Ashutosh Tiwari. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <climits>
#include <functional>
#include <unordered_map>
#include <tuple>
#include <iterator>
#include <unordered_set>
#include <chrono>
#include <regex>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
//    freopen("../in.txt", "r", stdin);
    int N, W;
    cin >> N >> W;
    vector<long long> dp(W + 1);
    for (int i = 0; i < N; i ++) {
        int w, v;
        cin >> w >> v;
        for (int j = W - w; j >= 0; j--)
            dp[j + w] = max(dp[j + w], dp[j] + v);
    }
//    long long ans = 0;
//    for (auto i: dp) ans = max(ans,i);
    cout << (*max_element(dp.begin(), dp.end()))<< endl;

    return 0;
}

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

using namespace std;
using ll =long long;
using db = double;

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; }

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(v) SORT(v);(v).erase(unique((v).begin(),(v).end()),(v).end())
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;

//ここから書き始める
int main()
{
	cout << setprecision(10);
	int n;
	cin >>n;
	vector<ll> v(n);
	rep(i,n) cin >> v[i];
	SORT(v);
	ll ans = 0;
	rep(i,n){
		ans += v[i];
	}
	if(ans % 10 != 0){
		cout << ans << endl;
		return 0;
	}
	else{
		rep(i,n){
			ans -= v[i];
			if(ans % 10 != 0) {
				cout << ans << endl;
				return 0;
			}else ans += v[i];
		}
	}
	cout << 0 << endl;

}


Measured memory_bytes: 256
import itertools

def main():
    n = int(input())

    ans = -10 ** 9
    f = [[0 for i in range(10)] for j in range(n)]
    p = [[0 for i in range(11)] for j in range(n)]

    for i in range(n):
        f[i] = [int(i) for i in input().split()]
    for i in range(n):
        p[i] = [int(i) for i in input().split()]

    ans = -float("inf")
    for i0, i1, i2, i3, i4, i5, i6, i7, i8, i9 in itertools.product(range(2), range(2), range(2),range(2), range(2), range(2),range(2), range(2), range(2), range(2)):
        i_list = [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9]
        if sum(i_list) != 0:
            value = 0
            for j in range(n):
                value += p[j][sum([i_list[_]*f[j][_] for _ in range(10)])]
            ans = max(ans, value)

    print(ans)


main()

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

int main(){
  int N,M;//N日、M個の宿題
  int sum = 0;

  cin >> N >> M;

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

  for(int i=0;i<M;i++){
    sum += A[i];
  }

  if(sum>N){
    cout << "-1" << endl;
  }else{
    cout << N - sum << endl;
  }
}

Measured memory_bytes: 3640
N = int(input())

k = N // 15
ans = 0

ans += 60 * k + 15 * 8 * int(k*(k-1)/2)

for i in range(15*k+1, N+1):
  if i%3 != 0:
    if i%5 != 0:
      ans += i
print(ans)

Measured memory_bytes: 9176
#include <iostream>
#include <string>
#include <algorithm>

#include <cstdio>

using namespace std;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string a,s;
    cin >> a >> s;
    
    if(a.size() > s.size())
    {
        cout << "GREATER" << endl;
        return 0;
    }
    else if(a.size() < s.size())
    {
        cout << "LESS" << endl;
        return 0;
    }
    else
    {
        for(int i = 0;i < a.size();++i)
        {
            if(a[i] > s[i])
            {
                cout << "GREATER" << endl;
                return 0;
            }
            else if(a[i] < s[i])
            {
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;

#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 REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

// vector<vector<int>> data(3, vector<int>(4));

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

  int n, k;
  cin >> n >> k;

  vector<int> vec;
  int buf;

  rep(i, n) {
    cin >> buf;
    vec.push_back(buf);
  }
  sort(vec.begin(), vec.end());

  int ans = 0;
  rep(i, k) { ans += vec[i]; }

  cout << ans;

  return 0;
}

Measured memory_bytes: 3620
n=int(input())
a=list(map(int,input().split()))
a.sort()
i=0
check=[0]*8
while i<n and a[i]<3200:
    a_i=a[i]
    for j in range(8):
        if check[j]==0 and a_i>=400*j and a_i<400*(j+1):
            check[j]=1
            break
    i+=1
if sum(check)==0:
    ans_min=1
    ans_max=n
else:
    ans_min=sum(check)
    ans_max=ans_min+n-i
print(ans_min,ans_max)

Measured memory_bytes: 3064
N, K = map(int, input().split())

int_num = {}
for i in range(N):
    a, b = map(int, input().split())
    if a in int_num:
        int_num[a] += b
    else:
        int_num[a] = b

for i, num in sorted(int_num.items(), key=lambda x:x[0]):
    K -= num
    if K <= 0:
        print(i)
        break

Measured memory_bytes: 15076
n,c,k = list(map(int,input().split()))

t = []
for i in range(n):
    t.append(int(input()))
t.sort()
a = t[0]
b = 1
ans = 1
for i in range(1,n):
    if t[i]-a <= k and b < c:
        b += 1
    else:
        ans += 1
        a = t[i]
        b = 1
print(ans)

Measured memory_bytes: 7384
N, K = map(int, input().split())

all = N*(N-1)//2
one = N-1
two = all - one

if K > two:
    print("-1")
    exit()

ans = []
for i in range(1,N):
    ans.append((i,N))

edge = []
for i in range(1,N):
    for j in range(i+1,N):
        edge.append((i,j))

for i in range(two - K):
    ans.append(edge[i])

print(len(ans))
for i in range(len(ans)):
    print("{0} {1}".format(ans[i][0],ans[i][1]))

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
 
int main(){
   int a,b,c,x,y;
   cin >> a >> b >> c >> x >> y;
   int min = 0;
   if(a+b >= 2*c){
       if(x > y and a < 2*c){
           min += 2*c*y;
           min += (x-y)*a;
       }else if(x > y and a > 2*c){
           min += 2*c*x;
       }else if(x < y and b > 2*c){
           min += 2*c*y;
       }else{
           min += 2*c*x;
           min += (y-x)*b;
       }
   }else{
       min = a*x + b*y;
   }
   cout << min << endl;
    
}
 

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

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i = 0; i < n; i++)
#define for1(i,n) for(int i = 1; i <= n; i++)
#define ford(i,n) for(int i = n-1; i >= 0; i--)
#define fore(i,a,b) for(int i = a; i <= b; i++)

using namespace std;

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


const  int MAXn= 3e5+5;
const  long long INF= 1e18;
const long long mod= 1e9+7;


int main(){
        int n,k;
        cin>>n>>k;
        string s;
        cin>>s;
       int happy=0;
       for(int i=0; i<n ;i++){
		    if((s[i]=='L'&& i==0) || (s[i]=='R' && i==n-1))
				continue;
				
			if(s[i]=='L'){
				if(s[i-1]=='L') happy++;
			}
			else if(s[i]=='R'){
				if(s[i+1]=='R') happy++;
			}
		}
		ll ans= min(n-1 , happy + 2*k);
		cout<<ans;
       
	}
			
			
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>

#define ll long long

using namespace std;

const long long mod = 1e9 + 7;

int main() {
	string s;
    cin >> s;
    const char* schar = s.c_str();
    int* countL;
    int* countR;
    countL = new int[s.length()];
    countR = new int[s.length()];

    //左にある連続したRの個数を調べる
    int r = 0;
    for(int i = 0; i < s.length(); i++){
        countR[i] = r;
        if(schar[i] == 'R') r++;
        else r=0;
    }

    //右にある連続したLの個数を調べる
    int l = 0;
    for(int i = s.length()-1; i >= 0; i--){
        countL[i] = l;
        if(schar[i] == 'L') l++;
        else l = 0;
    }

    for(int i = 0; i < s.length(); i++){
        int ans = 0;

        if(countR[i]){
            if(schar[i] == 'L'){
                ans++;
                ans += countR[i]/2;
            }else if(countL[i]){
                ans += countR[i]/2;
            }
            
        }
        if(countL[i]){
            if(schar[i] == 'R'){
                ans++;
                ans += countL[i]/2;
            }else if(countR[i]){
                ans += countL[i]/2;
            }
        }

        cout << ans << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main()
{
int i;
int x,y;
scanf("%d%d",&x,&y);
for(i=10;y>=i;i*=10);
x=x*i+y;
for(i=1;x>i*i;i++);
if(x==i*i) printf("Yes\n");
else printf("No\n");
return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;

int main(){
	ll k;
	ll a[100100];
	ll mi,ma;
	cin>>k;
	REP(i,k)cin>>a[i];
	for(int i=k-1;i>=0;i--){
		if(i==k-1){
			if(a[i]!=2){
				cout<<-1<<endl;
				return 0;
			}
			mi=2;ma=3;
		}else{
			if(ma<a[i]){
				cout<<-1<<endl;
				return 0;
			}
			ll t=(mi+a[i]-1)/a[i]*a[i];
			mi=t;
			ma=ma/a[i]*a[i]+a[i]-1;
			if(mi>ma){
				cout<<-1<<endl;
				return 0;
			}
		}
	}
	cout<<mi<<" "<<ma<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

        signed main() {
        int n,x,l;
       
        cin>>n;
         pair<int,int> p[n];
        for(int i=0;i<n;i++){
            cin>>x>>l;
            p[i]=make_pair(x+l,x-l);
        }
        sort(p,p+n);
        priority_queue<int> que;
        int ans=0,k=p[0].second;
        for(int i=0;i<n;i++){
            if(k<=p[i].second){
                ans++;
                k=p[i].first;
            }
        }
        cout<<ans;
         return 0;

        }


Measured memory_bytes: 1792
import java.util.Scanner;

class Main{
	public static void main(String[] args){
    	
      Scanner sc = new Scanner(System.in);
      String isOk = "NO" ;
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      
      if(a==5){
      	if(b==7){
        	if(c==5){
            	isOk = "YES";
            }
        } else if (b==5){
        	if(c==7){
            	isOk = "YES";
            }
        }
        
      } else if (a==7){
      		if(b==5){
            	if(c==5){
                	isOk = "YES";
                }
            }
      }
    
      System.out.println( isOk );
    }

}

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

using namespace std;

int c[5][5];

int main(){
    for(int i=1;i<=3;i++)
    for(int j=1;j<=3;j++)
    cin>>c[i][j];
    int b11,b12,b13,b21,b22,b23,b31,b32,b33;
    for(int a1=0;a1<=100;a1++)
    {
        b11=c[1][1]-a1;
        b21=c[1][2]-a1;
        b31=c[1][3]-a1;
        for(int a2=0;a2<=100;a2++)
        {
            b12=c[2][1]-a2;
            b22=c[2][2]-a2;
            b32=c[2][3]-a2;
            if(b11!=b12 || b21!=b22 || b31!=b32)
            continue;   
            for(int a3=0;a3<=100;a3++)
            {
            b13=c[3][1]-a3;
            b23=c[3][2]-a3;
            b33=c[3][3]-a3;
            if(b11==b13 && b21==b23 && b31==b33)
            {
            cout<<"Yes";
            return 0;
            }
            }
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
input_str = input()
head = input_str[:len(input_str) // 2]
tail = input_str[:(len(input_str)-1) // 2:-1]

ans = 0
for i in range(0, len(input_str) // 2):
    if head[i] != tail[i]:
        ans += 1

print(ans)
exit(0)


Measured memory_bytes: 3060
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

A,B,C = map(int,input().split())

if C >= A and C <= B:
    print("Yes")
else:
    print("No")

    


Measured memory_bytes: 6348
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int h, w;
  cin >> h >> w;
  int dx[4]{-1, 0, 1, 0};
  int dy[4]{0, -1, 0, 1};

  vector<string> vec(h);
  rep(i, 0, h) cin >> vec[i];

  rep(i, 0, h) {
    rep(j, 0, w) {
      if (vec[i][j] == '.')
        continue;
      bool is_ok = false;
      rep(k, 0, 4) {
        int x = j + dx[k], y = i + dy[k];
        if (x < 0 || x >= w || y < 0 || y >= h)
          continue;
        if (vec[y][x] == '#') {
          is_ok = true;
          break;
        }
      }
      if (!is_ok) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

vector<int64> MoAlgorithm(
    int n,
    const vector<tuple<int, int>>& queries,
    function<void(int)> add_fn,
    function<void(int)> delete_fn,
    function<int64(void)> query_fn) {
  vector<tuple<int, int, int>> indexed_queries;
  for (int i = 0; i < queries.size(); i++) {
    const auto [l, r] = queries[i];
    indexed_queries.push_back({i, l, r});
  }

  int bucket_size = sqrt(n);
  sort(
      indexed_queries.begin(), indexed_queries.end(),
      [&](const auto& t1, const auto& t2) {
        const auto [i1, l1, r1] = t1;
        const auto [i2, l2, r2] = t2;
        int b1 = l1 / bucket_size;
        int b2 = l2 / bucket_size;
        return make_pair(b1, r1) < make_pair(b2, r2);
      });
  
  vector<int64> answers(queries.size());
  int c_l = 0;
  int c_r = 0;
  for (const auto [i, l, r] : indexed_queries) {
    while (l < c_l) {
      c_l--;
      add_fn(c_l);
    }
    while (c_r < r) {
      add_fn(c_r);
      c_r++;
    }
    while (c_l < l) {
      delete_fn(c_l);
      c_l++;
    }
    while (r < c_r) {
      c_r--;
      delete_fn(c_r);
    }
    answers[i] = query_fn();
  }
  return answers;
}


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

  int n, q;
  cin >> n >> q;

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

  vector<tuple<int, int>> queries;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    queries.push_back({l, r});
  }

  vector<int> counts(n);
  int unique_count = 0;
  auto add_fn = [&](int i) {
    if (counts[cs[i]] == 0) {
      unique_count++;
    }
    counts[cs[i]]++;
  };
  auto delete_fn = [&](int i) {
    counts[cs[i]]--;
    if (counts[cs[i]] == 0) {
      unique_count--;
    }
  };
  auto query_fn = [&]() -> int64 {
    return unique_count;
  };

  vector<tuple<int, int, int>> indexed_queries;
  for (int i = 0; i < queries.size(); i++) {
    const auto [l, r] = queries[i];
    indexed_queries.push_back({i, l, r});
  }

  int bucket_size = sqrt(n);
  sort(
      indexed_queries.begin(), indexed_queries.end(),
      [&](const auto& t1, const auto& t2) {
        const auto [i1, l1, r1] = t1;
        const auto [i2, l2, r2] = t2;
        int b1 = l1 / bucket_size;
        int b2 = l2 / bucket_size;
        return make_pair(b1, r1) < make_pair(b2, r2);
      });
  
  vector<int64> answers(queries.size());
  int c_l = 0;
  int c_r = 0;
  for (const auto [i, l, r] : indexed_queries) {
    while (l < c_l) {
      c_l--;
      add_fn(c_l);
    }
    while (c_r < r) {
      add_fn(c_r);
      c_r++;
    }
    while (c_l < l) {
      delete_fn(c_l);
      c_l++;
    }
    while (r < c_r) {
      c_r--;
      delete_fn(c_r);
    }
    answers[i] = query_fn();
  }

  for (int i = 0; i < q; i++) {
    cout << answers[i] << "\n";
  }
}

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

void dfs( vector<vector<bool>>& gr, vector<bool>& vf, int node ) {
	vf[node] = true;

	for( int i = 1; i < gr.size(); ++i ) {
		if( gr[node][i] && !vf[i] ) {
			dfs( gr, vf, i );
		}
	}
}

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

	int N, M;
	cin >> N >> M;

	vector<vector<bool>> gr( N+1, vector<bool>( N+1 ) );
	vector<pair<int, int>> eg( M );
	for( int i = 0; i < M; ++i ) {
		int a, b;
		cin >> a >> b;

		gr[a][b] = true;
		gr[b][a] = true;

		eg[i] = { a, b };
	}

	int result = 0;
	for( int i = 0; i < M; ++i ) {
		int a = eg[i].first;
		int b = eg[i].second;

		gr[a][b] = false;
		gr[b][a] = false;

		vector<bool> vf( N+1 );
		dfs( gr, vf, 1 );

		int cv = 0;
		for( int j = 1; j <= N; ++j ) {
			cv += vf[j];
		}

		result += cv < N;

		gr[a][b] = true;
		gr[b][a] = true;
	}

	cout << result << endl;
	return 0;
}


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

#define rep(i, e) for (int i = 0; i < e; i++)
#define repp(i, s, e) for (int i = s; i < e; i++)
#define N_Max 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long

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;
}

const long long INF = 1LL << 60;

int main()
{
    int n, m, a, b, c, d, k, x;
    ll cnt = 1, ans = 0;
    vector<vector<int>> v(100005, vector<int>());
    priority_queue<ll> pq;
    scanf("%d%d", &n, &m);
    rep(i, n)
    {
        cin >> a >> b;
        v[a].push_back(b);
    }
    repp(i, 1, m + 1)
    {
        rep(j, v[i].size())
        {
            pq.push(v[i][j]);
        }
        if (!pq.empty())
        {
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >> n;
  n=n%1000;
  if(n==0)cout << 0 << endl;
  else cout << 1000-n << endl;

}

Measured memory_bytes: 3632
fun main(A: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toInt() }
    val sum = a.sum()
    println(if (a.count { it * 4 * m >= sum } >= m) "Yes" else "No")
}


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

vector< vector<int> > g;

string possible() {
    string ans = "OK";
    for (int i = 0; i < g.size(); i++) {
        if (g[i].size() % 2 == 1) {
            ans = "NG";
            break;
        }
    }
    return ans;
}

int main() {
    int a, b;
    while (cin >> a >> b) {
        g.resize(101);
        if (a == 0 && b == 0) {
            g[1].push_back(2);
            g[2].push_back(1);
//            for (int i = 0; i < 5; i++) {
//              cout << i << ": ";
//              for (int j = 0; j < g[i].size(); j++) {
//                  cout << g[i][j] << ' ';
//              }
//              cout << endl;
//            }
            cout << possible() << endl;
            for (int i = 0; i < g.size(); i++) {
                g[i].clear();
                g[i].resize(0);
            }
            g.clear();
        } else {
            g[a].push_back(b);
            g[b].push_back(a);
        }
   }
    return 0;
}

        

Measured memory_bytes: 0
#include<stdio.h>

int min(int,int);

int main(void){
  int a,b,c,d,e;

  scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);

  printf("%d\n",min(a,min(b,c))+min(d,e)-50);

  return 0;
}

int min(int x,int y){
  return x<y?x:y;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int dp[50050];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;cin>>n>>m;
  int c[m];
  FOR(i,0,m)cin>>c[i];
  sort(c,c+m);
  FOR(i,0,n+1)dp[i]=1e9;
  dp[0]=0;
  FOR(i,0,m){
    FOR(j,0,n+1){
      if(dp[j]!=1e9){
        if(j+c[i]<=n){
          dp[j+c[i]]=min(dp[j+c[i]],dp[j]+1);
        }
      }
    }
  }
  cout<<dp[n]<<endl;
  return 0;
}


Measured memory_bytes: 3404
package main

import "fmt"

func main() {
	var S string
	fmt.Scanf("%s", &S)

	ss := make([]string, len(S))
	for i := range ss {
		ss[i] = string(S[i])
	}
	var count int
	for i := 0; i < len(S); i++ {
		if i == len(S)-1 {
			break
		}
		if ss[i] == ss[i+1] {
			if ss[i] == "1" {
				ss[i+1] = "0"
			} else {
				ss[i+1] = "1"
			}
			count++
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

char albt[26] = {'a','b','c','d','e','f','g','h','i','j','k','l',
                 'm','n','o','p','q','r','s','t','u','v','w','x',
                 'y','z'};

//vector<ll> g[202020];
//fill(score, score+202020, 0);
//vector<ll> v;

int main(){
  ll n,q;
  cin >> n >> q;
  
  vector<tll> koji;
  for (int i=0;i<n;i++){
    ll s, t, x;
    cin >> s >> t >> x;
    koji.push_back(tll(s-x,1,x));
    koji.push_back(tll(t-x,-1,x));
    //cout << s-x << " " << 1 << " " << x << endl;
    //cout << t-x << " " << -1 << " " << x << endl;
  }
  
  sort(koji.begin(), koji.end());
  //cout << get<0>(koji[0]) << get<1>(koji[0]) << endl;
  
  ll now = 0;
  multiset<ll> mset;
  
  ll time = -INF;
  ll action;
  ll xx;
  ll d;
  
  for (int i=0;i<q;i++){
    cin >> d;
    //cout << "current time: " << d << endl;
    
    while(now < koji.size()){
      time = get<0>(koji[now]);
      action = get<1>(koji[now]);
      xx = get<2>(koji[now]);
      //cout << time << " " << action << " " << xx << endl;
      
      if(time > d) break;
      else{
        if (action == 1) mset.insert(xx);
        else if (action == -1) mset.erase(xx);
        now++;
      }
    }
    
    if (mset.empty()) cout << -1 << endl;
    else cout << *(mset.begin()) << endl;
  }
}

Measured memory_bytes: 21736
#include <stdio.h>
#include <string.h>
 
char str[110];
int i,j,k,l,m,n;
int n,e,s,w;
int a[105][7],b[105][7];
int t;
 
void input() {
 
  scanf("%d",&n);
 
  for(j=0;j<n;j++){
  for(i=0;i<6;i++){
    scanf("%d",&a[j][i+1]);
    b[j][i+1] = a[j][i+1];
  }
  }
}
 
void N() {
  t = a[m][1];
  a[m][1] = a[m][2];
  a[m][2] = a[m][6];
  a[m][6] = a[m][5];
  a[m][5] = t;
}
 
void S() {
  t = a[m][1];
  a[m][1] = a[m][5];
  a[m][5] = a[m][6];
  a[m][6] = a[m][2];
  a[m][2] = t;
}
 
void E() {
  t = a[m][1];
  a[m][1] = a[m][4];
  a[m][4] = a[m][6];
  a[m][6] = a[m][3];
  a[m][3] = t;
}
 
void W() {
  t = a[m][1];
  a[m][1] = a[m][3];
  a[m][3] = a[m][6];
  a[m][6] = a[m][4];
  a[m][4] = t;
}
 
void UF() {
 
  if(a[k][1] == a[m][1]) { 
    if(a[k][2] == a[m][3]) strcpy( str, "NWS");
    else if(a[k][2] == a[m][5]) strcpy(str ,"NEES");
    else if(a[k][2] == a[m][4]) strcpy(str,"NES");
 
 
  }  else if(a[k][1] == a[m][2]) { 
    if(a[k][2] == a[m][3])  strcpy( str, "NWS");
    else if(a[k][2] == a[m][1] ) strcpy(str ,"NEES");
    else if(a[k][2] == a[m][4]) strcpy(str,"NES");
    N();
 
 
  } else if(a[k][1] == a[m][3]){ 
    if(a[k][2] == a[m][6])  strcpy( str, "NWS");
    else if(a[k][2] == a[m][5])  strcpy(str ,"NEES");
    else if(a[k][2] == a[m][1]) strcpy(str,"NES");
    W();
 
 
  } else if(a[k][1] == a[m][4]) {
    if(a[k][2] == a[m][1]) strcpy( str, "NWS");
    if(a[k][2] == a[m][5])  strcpy(str ,"NEES");
    if(a[k][2] == a[m][6]) strcpy(str,"NES");
    E();
 
 
  } else if(a[k][1] == a[m][5]) {
    if(a[k][2] == a[m][3]) strcpy( str, "NWS");
    else if(a[k][2] == a[m][6])  strcpy(str ,"NEES");
    else if(a[k][2] == a[m][4]) strcpy(str,"NES");
    S();
 
 
  } else if(a[k][1] == a[m][6]) {
    if(a[k][2] == a[m][3]) strcpy( str, "NWS");
    else if(a[k][2] == a[m][2])  strcpy(str ,"NEES");
    else if(a[k][2] == a[m][4]) strcpy(str,"NES");
    N();
    N();
  }
 
 
}
 
 
void output() {
 
  if(l == 6) printf("No\n");
  else printf("Yes\n");
}
 
void IF() {
 
  for(i=0;i<strlen(str);i++) {
 
    if(str[i] == 'N') N();
    else if(str[i] == 'S') S();
    else if(str[i] == 'W') W();
    else if(str[i] == 'E') E();
  }
}
 
int main() {
 
 
  input();
 
  for(k=0;k<n;k++) {
    for(m=0; m<n;m++) {
 
    UF();
     
    IF();
 
    l=0;
 
    if(k != m) {
    for(i=1; i<=6;i++) {
      if(a[k][i] == a[m][i]) l++;
    }
    }
 
    if(l == 6) break;
 
    }
    if(l ==6) break;
  }
 
   
    output();
 
 
 
 
  return 0;
}


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

using namespace std;

const string Display[10] = {
	"0111111",
	"0000110",
	"1011011",
	"1001111",
	"1100110",
	"1101101",
	"1111101",
	"0100111",
	"1111111",
	"1101111"
};


int main() {
	int n, d;
	string now;

	while (cin >> n, n != -1) {
		now = "0000000";
		for (int i = 0; i < n; ++i) {
			cin >> d;
			//cout << d << endl;
			for (int i = 0; i < 7; ++i) {
				cout << (now[i]^Display[d][i]);
			}
			cout << endl;
			now = Display[d];
		}
	}

	return 0;
}


Measured memory_bytes: 3000
s = input()

if len(s) < 26:
    # sに含まれていない文字の中で辞書順最小のものを付け加えれば良い
    for i in range(26):
        candi_ch = chr(ord('a') + i)
        if candi_ch not in s:
            print(s + candi_ch)
            exit()
else:
    for i in reversed(range(1, 26)):
        if s[i-1] < s[i]:
            s1 = s[0:i-1]
            for j in range(26):
                candi_ch = chr(ord('a') + j)
                if candi_ch > s[i-1] and candi_ch not in s1:
                    print(s1 + candi_ch)
                    exit()
    
    print(-1)


Measured memory_bytes: 3064
def cmb(n, k):
  s = 1
  for j in range(n - k + 1, n + 1, 1):
    s *= j
  for j in range(1, k+1):
    s //= j
  return s

n, p = map(int, input().split())
aa = list(map(lambda x: int(x) % 2, input().split()))
odd = sum(aa)
even = n - odd
if p == 0:
  c = 2**even * sum(cmb(odd, k) for k in range(0, odd+1, 2))
  print(c)
else:
  c = 2**even * sum(cmb(odd, k) for k in range(1, odd+1, 2))
  print(c)


Measured memory_bytes: 3064
import java.util.*;

public class Main {
	static final long MOD = 1000000007;
	static Scanner sc = new Scanner(System.in);
	static long[] f = null;
	static long[] fInverse = null;
	
	public static void main(String[] args) {
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		if((x + y) % 3 != 0) {
			System.out.println(0);
			return;
		}
		
		int sz = (x + y) / 3;
		f = new long[sz + 1];
		fInverse = new long[sz + 1];
		for(int i = 0; i <= sz; ++i) {
			f[i] = (i < 2) ? 1 : f[i - 1] * i % MOD;
			fInverse[i] = calcModInv(f[i]);
		}
		
		long ans = 0;
		for(int a = 0; a <= sz; ++a) {
			int b = sz - a;
			int xx = a + 2 * b;
			int yy = 2 * a + b;
			
			if(xx == x && yy == y) ans = (ans + comb(sz, a)) % MOD;
		}
		
		System.out.println(ans);
	}
	
	static long comb(int n, int r) {
		return f[n] * fInverse[r] % MOD * fInverse[n - r] % MOD;
	}
	
	static long calcModInv(long n) {
		long[] s = new long[2];
		solve(n, MOD, s);
		return (s[0] >= 0) ? s[0] : s[0] + MOD;
	}
	
	static void solve(long a, long b, long[] res) {
		if(a < b) solve(b, a, res);
		
		if(b == 0) {
			res[0] = 1;
			res[1] = 0;
			return;
		}
		
		solve(b, a % b, res);
		long tmp = res[0] % MOD;
		res[0] = res[1] % MOD;
		res[1] = tmp - a / b % MOD * res[1] % MOD;
	}
}

Measured memory_bytes: 57292
class cmbs(object):
    def __init__(self, mod):
        self.mod = mod
        self.g1 = [1, 1]
        self.g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, 2 * (10 ** 6) + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)

    def cmb(self, n, r):
        if n > 2 * (10 ** 6):
            return self.cmbl(n, r)
        return self.cmbr(n, r)

    def cmbr(self, n, r):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod

    def cmbl(self, n, r):
        t = 1
        r = min(r, n-r)
        for i in range(n - r + 1, n + 1):
            t = t * i % self.mod
        return t * self.g2[r] % self.mod
def main():
    K = int(input())
    S = input()
    l = len(S)
    mod = 10**9 + 7
    c = cmbs(mod)
    r = 0
    x25 = 1
    x26 = pow(26, K, mod)
    inv26 = pow(26, mod-2, mod)
    for i in range(K+1):
        r = (r + c.cmb(l+i-1, i) * x25 * x26) % mod
        x25 = x25 * 25 % mod
        x26 = x26 * inv26 % mod
    return r % mod
print(main())


Measured memory_bytes: 226916
N=1e7,a[10010000];main(i,j){for(i=j=2;i*i<N;a[i]||j>N?j=++i:a[j+=i]++);for(;i=~scanf("%d",&j);j&&printf("%d\n",j))for(;a[j]+a[j-2]+a[j-6]+a[j-8];j--);}

Measured memory_bytes: 0
h,w = map(int,input().split())
a=["."*(w+2)]
for i in range(h):
    arr = "."+str(input())+"."
    a.append(arr)
a.append("."*(w+2))

for i in range(1,h+1):
    for j in range(1,w+1):
        if a[i][j] == "#" and a[i][j-1] == a[i][j+1] == a[i+1][j] == a[i-1][j] == ".":
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
    int x, y;

    while (true) {
        cin >> x >> y;
        if (x == 0 && y == 0) break;
        if (x > y)
            swap(x, y);
        cout << x << " " << y << endl;
    }

    return 0;
}


Measured memory_bytes: 2988
#include<stdio.h>
int main(void){
  int n,t,r[2][100],i,minc=1001;
  scanf("%d%d",&n,&t);
  for(i=0;i<n;i++)scanf("%d%d",&r[0][i],&r[1][i]);
  for(i=0;i<n;i++){
    if(r[1][i]<=t){
      if(r[0][i]<minc)minc=r[0][i];
    }
  }
  if(minc==1001){
    printf("TLE");
  }
  else printf("%d",minc);
  return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }

const int MAX_N = 200000;
int n;
ll k;
ll a[MAX_N+1];
ll s[MAX_N+1];

int main()
{
  fastio();

  cin >> n >> k;
  forn1(i,n) cin >> a[i];

  forn1(i,n) {
    s[i] = s[i-1] + a[i];
  }

  ll ans = 0;

  int total = 1;
  map<int,int> cnt;
  cnt[0] = 1;

  for (int i = 1; i <= n; i++) {
    if (total == k) {
      int j = i - k;
      int v = (s[j] - j) % k;
      cnt[v]--;
      total--;
    }

    int v = (s[i] - i) % k;
    ans += cnt[v];
    cnt[v]++;
    total++;

    /*
      for (int i = 0; i < k; i++) {
      printf("cnt[%d]=%d ",i,cnt[i]);
      }
      puts("\n");
    */
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    cout << 180 * (n - 2) << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int sum = 0;
		int sum_digit = 0;
		int j;

		//1からn(iとする)まで繰り返す
		for (int i = 1; i <= n; i++) {
//			System.out.println(i+"回目");
			//jの各桁の和を計算(sum_digitとする)
			//自然数の各桁の和を計算
			j = i;
			while (j != 0) {
				//sumDigitsは単独ではloopしないので、while loopを使う。
				sum_digit += j % 10;
				//再右端の桁を得るために%10を利用する。
				j /= 10;
				//再右端の桁を取り除くためにn/=10を利用する。
			}
			//a<sum_digit<bならばsumに追加
			if (a <= sum_digit && sum_digit <= b) {
//				System.out.println(i+"を足します");
				sum += i;
//				System.out.println(sum+"になりました");
			}
			sum_digit=0;
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll n;
  string s;
  cin >> n >> s;
  ll wcnt = 0;
  ll rcnt = 0;
  rep(i, n) {
    if (s.at(i) == 'W') wcnt++;
    if (s.at(i) == 'R') rcnt++;
  }
  ll ans = 0;
  rep(i, rcnt) {
    if (s.at(i) == 'W') ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3728
import java.util.*;
import java.lang.*;
import java.io.*;
 
class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
    	//  W <= 300
    	String sh = "##############################################################################################################################################################################################################################################################################################################";
    	String dt = "..............................................................................................................................................................................................................................................................................................................";
        String u, nl = System.getProperty("line.separator");
        StringBuilder
            p = new StringBuilder(1000),
            k = new StringBuilder(100);
        Scanner r = new Scanner(System.in);
        int h, w;
        while (0 != ((h = r.nextInt()) | (w = r.nextInt()))) {
            p.append(u = sh.substring(0, w)).append(nl);
            k.setLength(0);
            k.append(dt.substring(0, w)).append(nl)
            .replace(0, 1, "#").replace(w - 1, w, "#");
            while (2 != h--) {
                p.append(k);
            }
            p.append(u).append(nl).append(nl);
        }
        System.out.print(p);
    }
}

Measured memory_bytes: 18356
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <unordered_map>
#include <limits>

std::vector<std::vector<int>> dp;

std::vector<std::array<int,3>> cost;

int sol ( int i, int j ) {
  if ( dp[i][j] != -1 ) return dp[i][j];

  int rtn = std::numeric_limits<int>::min();
  for (int a=0; a<3; a++) {
    if ( j == a ) continue;
    rtn = std::max(rtn, (sol(i-1, a) + cost[i][a]));
  }

  return dp[i][j] = rtn;
}


int main (void) {

  int N;
  std::cin >> N;

  cost.resize(N+1);
  for(int i=1; i<N+1; i++) std::cin >> cost[i][0] >> cost[i][1] >> cost[i][2];

  dp.resize(N+1); for(int i=0; i<N+1; i++) dp[i].assign(3, -1);
  for(int i=0; i<3; i++) dp[0][i] = 0;

  int ans = std::max( { sol(N,0), sol(N,1), sol(N,2) } );
  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 14720
from collections import deque

S = deque(input())
Q = int(input())
reverse = 1


for i in range(Q):
    
    q = input()
    
    if (q == '1'):
        reverse *= -1
    else:
        integer, judge, cha = q.split()
        
        if (judge == '1'):
            if (reverse == 1):
                S.appendleft(cha)
            else:
                S.append(cha)
        
        elif (judge == '2'):
            if (reverse == 1):
                S.append(cha)
            else:
                S.appendleft(cha)

if (reverse == -1):
    S.reverse()

print(''.join(list(S)))

Measured memory_bytes: 8436
#!/usr/bin/env python3
def right_triangle(edge):
    # a < b < c
    return (edge[0] ** 2 + edge[1] ** 2 == edge[2] ** 2)

n = int(input())
for i in range(n):
    edge = sorted([int(x) for x in input().split()])
    if right_triangle(edge):
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 6720
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;
#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define LLINF = (1LL<<62)
typedef long long ll;
int inf = 1<<30;

int main()
{
  int N;
  cin >> N;
  
  int A[N];

  int r = 0;
  int rr = 0;

  REP(i,N){
    cin >> A[i];
    if (i!=0 && A[i] == A[i-1]){
      rr += 1;
    }
    else if(i!=0){
      r += (rr+1)/2;
      rr = 0;
    }
  }
  r += (rr+1)/2;

  cout << r << endl;

  return 0;
}


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

//ライブラリ始まり

//定数

//円周率
const double PI = 3.1415926535897932384;

//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15

//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";

//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造

//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す
    return SIZE.at(root(x));
  }
};

//関数

//ctoi
int ctoi(char c){
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  } 
  if (c == '2') {
    return 2;
  } 
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  } 
  if (c == '5') {
    return 5;
  } 
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  } 
  if (c == '8') {
    return 8;
  } 
  if (c == '9') {
    return 9;
  }
  return -1;  
}

//素数判定
bool PN(int x) {
  if (x <= 1) {
    return false; // 1や0,-1は素数ではない
  }
  if (x == 2) {
    return true; // √2 + 1 > 2 なので下でやると 2 ％ 2 = 0 となり判定できない
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false; // 割れたら素数じゃない
    }
  }
  return true;
}

//ライブラリ終わり

int main() {
  int N;
  cin >> N;
  vector<int> T(N, 1);
  for (int i = 2; i <= N; i++) {
    int M = i;
    for (int j = 2; j < sqrt(i) + 1; j++) {
      while (M % j == 0) {
        T.at(j - 1)++;
        M /= j;
      }
    }
    if (M != 1) {
      T.at(M - 1)++;
    }
  }
  ll ans = 1;
  for (int i = 0; i < N; i++) {
    ans *= T.at(i);
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
string sed(string a,string l,string r){
  if(a.size()<l.size()) return a;
  else if(string(a.begin(),a.begin()+l.size())==l)
    return r+sed(string(a.begin()+l.size(),a.end()),l,r);
  else return a[0]+sed(string(a.begin()+1,a.end()),l,r);
}
int main(void)
{
  for(;;){
    int n;
    cin >> n;
    if(!n) return 0;
    vector<pair<string,string> > arg(n);
    REP(i,n) cin >> arg[i].first >> arg[i].second;
    string s,g;
    cin >> s >> g;
    map<string,int> dic;
    dic.clear();
    priority_queue<pair<int,string> > dijk;
    dijk.push(make_pair(0,s));
    while(!dijk.empty()){
      int ncos;
      string tmps;
      tie(ncos,tmps)=dijk.top();
      dijk.pop();
      if(tmps.size()>g.size()||dic.count(tmps)) continue;
      dic[tmps]=-ncos;
      REP(i,n) dijk.push(make_pair(ncos-1,sed(tmps,arg[i].first,arg[i].second)));
    }
    if(dic.count(g)) cout << dic[g] << endl;
    else cout << -1 << endl;
  }
}

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

int main() {

    const int p = 3;
    vector<int> x(p);
    for (int i = 0; i < p; i++) cin >> x[i];
    sort(x.begin(), x.end());
    
    int diff = x[2] - x[0] + x[2] - x[1];
    int ans;
    if (diff % 2 == 0) {
        ans = diff / 2;
    }
    else {
        ans = (diff + 1) / 2 + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*

Coded by peyha X

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

string t;
int n;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> t;
	
	n = t.size();
	
	for(int i = 0; i< n; i++)
		if(t[i] == '?')
			t[i] = 'D';
	
	cout << t << '\n';
	
}


Measured memory_bytes: 3740