akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int MAX_N=100005;
int a[MAX_N][3];
int dp[MAX_N][3];
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<3;j++)
		{
			dp[i][j]=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+a[i][j];
		}
	}
	cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<endl;
	return 0;
}


Measured memory_bytes: 2560
import copy

def blackCount(x):
  cc=0
  pp=len(x)
  for l in range(pp):
    cc+=x[l].count('#')
  return cc

def rowChange(x,row):
  ss=list(x[row])
  for l in range(w):
    ss[l]='.'
  x[row]="".join(ss)
  
def colChange(x,col):
  for l in range(h):
    ss=list(x[l])
    ss[col]='.'
    x[l]="".join(ss)

h,w,k=map(int,input().split())
c=[]
count=0
for i in range(h):
  c.append(input())
  
for i in range(2**h):
  for j in range(2**w):
    c2=copy.deepcopy(c)
    for a in range(h):
      if (i>>a)%2==1:
        rowChange(c2,a)
        
    for b in range(w):
      if (j>>b)%2==1:
        colChange(c2,b)
    
    if blackCount(c2)==k:
      count+=1
      
print(count)

Measured memory_bytes: 9364
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD= 1000000007;
signed main() {
int n;
string s;
cin>>n>>s;
if(n%2){
  cout<<"No";
  return 0;
}
for(int i=0;i<n/2;i++){
  if(s[i]!=s[i+n/2]){
    cout<<"No";
    return 0;
  }
}
cout<<"Yes";
return 0;



}


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

int main(){
  int ano, mes,dia;
  scanf("%d/%d/%d",&ano, &mes, &dia);
  if(ano > 2019 || ano == 2019 && mes > 4 || ano == 2019 && mes == 4 && dia > 30) cout << "TBD" << '\n';
  else cout << "Heisei" << '\n';
  cout << '\n';
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T>
T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T>
T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T>
bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

const int INF = 1000000;

int N, A, B, C;
vector<int> l(8);

int dfs(int i, int a, int b, int c) {
    if (i == N) {
        if (min({a, b, c}) > 0) {
            return abs(A - a) + abs(B - b) + abs(C - c) - 30;
        } else {
            return INF;
        }
    }

    int ret0 = dfs(i + 1, a, b, c);
    int ret1 = dfs(i + 1, a + l[i], b, c) + 10;
    int ret2 = dfs(i + 1, a, b + l[i], c) + 10;
    int ret3 = dfs(i + 1, a, b, c + l[i]) + 10;

    return min({ret0, ret1, ret2, ret3});
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> A >> B >> C;
    REP(i, N) {
        cin >> l[i];
    }
    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n, m, ans = 0;
int a[N], b[N], c[N];
vector<pair<int, int> > v;

int32_t main()
{
	IOS;
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	for(int i = 1; i <= m; i++)
	{
		cin >> b[i] >> c[i];
		v.push_back({c[i], b[i]});
	}
	sort(v.rbegin(), v.rend());
	sort(a + 1, a + n + 1);
	int idx = 0;
	for(int i = 1; i <= n; i++)
	{
		if(idx >= m)
			ans += a[i];
		else
		{
			ans += max(a[i], v[idx].first);
			v[idx].second--;
			if(v[idx].second == 0)
				idx++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4336
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define li 100005
typedef long long int lo;
using namespace std;
lo n,m,cev,t;
vector< pair<lo,lo> > v;
pair<lo,lo> p[300005];
int main(){
	scanf("%lld %lld",&n,&t);
	for(int i=1;i<=n;i++){
		scanf("%lld %lld",&p[i].fi,&p[i].se);
		v.pb(mp(p[i].fi,p[i].se));
	}
	sort(v.begin(),v.end());
	for(int i=0;i<(int)v.size();i++){
		if(v[i].se<=t){
			printf("%lld",v[i].fi);
			return 0;
		}
	}
	printf("TLE");
	return 0;
}


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

int a[1010];

void sort(int l, int r) {
    if (l >= r) return;
    int p = l;
    int k = l+1;
    while (k <= r) {
        if (a[k] < a[l]) {
            swap(a[k], a[p+1]);
            p++;
        }
        k++;
    }
    swap(a[l], a[p]);
    sort(l, p);
    sort(p+1, r);
}

int main(void){
    int n;
    while (1) {
        cin >> n;
        if (!n) break;
        for (int i = 0; i < n; i++) cin >> a[i];
        sort(0,n-1);
        //for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
        
        int ans = 10101010;
        for (int i = 0; i < n-1; i++) if (ans > a[i+1] - a[i]) ans = a[i+1] - a[i];
        cout << ans << endl;
    }    
}

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

vector<int> A = {100, 101, 102, 103, 104, 105};

int solve(int indx, int sum)
{
    if(indx == A.size())
        return (sum == 0);

    for(int i=0; A[indx]*i<=sum; i++)
    {
        if(solve(indx+1, sum - A[indx]*i))
            return 1;
    }

    return 0;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int X;
    cin >> X;

    cout << solve(0, X) << "\n";
    return 0;
}


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

int main(){
	int N; cin>>N;
	string S; cin>>S;

	int r = 0;//r = depth
	int l = 0;
	for(char s:S){
		if(s == '(') r++;
		else{
			r--;
			if(r < 0){
				r = 0;
				l++;
			}
		}
	}

	string ls(l, '(');
	string rs(r, ')');
	cout<< ls + S + rs <<endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())

if k % 2 == 0:
    step = k // 2
    a = step
else:
    step = k
    a = step

ans = 0

while a <= n:
    b_num = c_num = (n+a)//k - a//k
    ans += b_num * c_num

    a += step

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>



int main(int argc, char* argv[])
{
  using std::cin;
  using std::cout;
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int N, X;
  cin >> N >> X;
  int D = 0;
  int res = 1;
  for (int i = 0; i < N; ++i)
  {
    int Li; cin >> Li;
    D += Li;
    if (D <= X) ++res;
  }

  cout << res << "\n";

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
ll dp[305][90005]={0};
ll dp2[305][90005]={0};
const ll mod=998244353;
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll ret=pow(x,y/2);
  ret*=ret;
  ret%=mod;
  if(y%2==1) ret*=x;
  return ret%mod;
}
int main(){
  ll n,sum=0;
  cin>>n;
  ll array[305]={0};
  for(ll i=1;i<=n;i++){
    cin>>array[i];
    sum+=array[i];
  }
  for(ll i=1;i<=n;i++){
    if(array[i]>=(sum+1)/2){
      cout<<0<<endl;
      return 0;
    }
  }
  const ll ferm=pow(2,mod-2);
  //cout<<ferm<<endl;
  for(ll i=0;i<n;i++){
    dp[i+1][array[i+1]]+=pow(2,n-1);
    dp2[i+1][array[i+1]]++;
    for(ll j=0;j<90005;j++){
      dp[i+1][j]+=dp[i][j];
      dp[i+1][j]%=mod;
      dp[i+1][j+array[i+1]]+=dp[i][j]*ferm;
      dp[i+1][j+array[i+1]]%=mod;

      dp2[i+1][j]+=dp2[i][j];
      dp2[i+1][j+array[i+1]]+=dp2[i][j];
      dp2[i+1][j]%=mod;
      dp2[i+1][j+array[i+1]]%=mod;
    }
  }
  ll ans=pow(3,n);
  for(ll i=(sum+1)/2;i<90005;i++) {
    ans-=dp[n][i]*3;
    if(ans<0){
      while(ans<0) ans+=mod;
    }
    ans%=mod;
  }
//  cout<<ans<<endl;
  if(sum%2==0){
   ans+=3*dp2[n][sum/2];
  }
  if(ans<0){
    while(ans<0) ans+=mod;
  }
  ans%=mod;
  /*for(int i=0;i<=n;i++){
    for(int j=0;j<5;j++) cout<<dp[i][j]<<" ";
    cout<<endl;
  }*/
//  if(sum%2!=0)cout<<ans<<endl;
  //else cout<<-1<<endl;
  cout<<ans<<endl;
}


Measured memory_bytes: 425472
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
template<class T> inline void dmin(T& x,T y){ y<x?x=y:0; }
template<class T> inline void dmax(T& x,T y){ y>x?x=y:0; }
template<class T> inline void dmin(T& x,vector<T> y){ 
	for(auto t:y) t<x?x=t:0;
}
template<class T> inline void dmax(T& x,vector<T> y){
	for(auto t:y) t>x?x=t:0;
}
int main(){
	string s; cin>>s;
	cout<<s.substr(0,3)<<endl;
	return 0;
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
using namespace std;

string s;
map< ll , ll > m;
ll ans,sum,pot=1;

int main()
{

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

    cin >> s;
    m[0] = 1;
    for(ll i=s.size()-1; i>=0; i--){
        char l = s[i];
        sum+=(l-'0')*pot;
        sum%=2019;
        pot*=10;
        pot%=2019;
        if( m.count( sum ) ) ans+=m[ sum ];
        m[ sum ]++;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 3772
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int P = sc.nextInt();
        
        int kakera = A * 3 + P;
        
        System.out.println(kakera/2);
    }
}


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

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

	int a[100000] = { 0 };
	for (int n = 1; n <= N; n++) {
		int i = 0;
		while (n * pow(2, i) < K) i++;
		a[n - 1] = i;
	}

	double p = 0;
	for (int i = 0; i < N; i++) {
		p += 1 / (pow(2, a[i]));
	}
	p /= N;

	printf("%.10lf\n", p);

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i=s;i<n;++i)
#define drep(i,s,n) for (int i=n;i>=s;--i)
#define all(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;

int gcd(int a,int b)
{if (a%b == 0) return(b);
 else          return(gcd(b,a%b));}
int lcm(int a,int b)
{return a*b/gcd(a,b);}
void printv(vector<auto> v) {cout<<'[';rep(i,0,v.size()){cout<<v[i]<<',';}cout<<']'<<endl;}
void printvv(vector<vector<auto>> vv)
{
  cout<<'['<<endl;
  rep(q,0,vv.size()){cout<<'[';rep(p,0,vv.at(q).size())cout<<vv.at(q).at(p)<<',';cout <<']'<<endl;}
  cout<<']'<<endl;
}
void solve(); int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}
int step_x[] = {-1,0,0,1};
int step_y[] = {0,-1,1,0};
int INF=10e5;
//------------------------------------------------------------
int N,M,ans=0;
string S;

void solve() {
  cin>>S;

  char pre;
  rep(i,0,S.size())
  {
    if(S[i]=='?')
    {
      S[i]='D';
    }

  }
  print(S);
  return;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K;
  vector<int> A(3); 

  cin >> A.at(0) >> A.at(1) >> A.at(2) >> K ;

  sort(A.begin(),A.end());
  
  for(int i=0;i<K;i++) A.at(2)*=2;

  cout << A.at(0) + A.at(1) + A.at(2) << endl;
 
  return 0;
}

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

 struct Node {
    int key;
    Node *right, *left, *parent;
    };

 Node *root, *NIL;

Node * find(Node *u, int k) {
     while ( u != NIL && k != u->key ) {
        if ( k < u->key ) u = u->left;
        else u = u->right;
         }
    return u;
     }
 void insert(int k) {
    // ALDS1_8_A 解答例を参照してください。
     Node *y = NIL;
     Node *x = root;
     Node *z;
     z = (Node *)malloc(sizeof(Node));
     z->key = k;
     z->left = NIL;
     z->right = NIL;
     while ( x != NIL ) {
         y = x;
         if ( z->key < x->key ) {
             x = x->left;
         } else {
             x = x->right;
         }
     }
    z->parent = y;
     if ( y == NIL ){
         root=z;
     }else{
         if(z->key < y->key){
             y->left =z;
         }else{
             y->right=z;
         }
         }
     }

void inorder(Node *u) {
    // ALDS1_8_A 解答例を参照してください。
    if ( u == NIL ) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
     }
void preorder(Node *u) {
if ( u == NIL ) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}



int main() {
    int n, i, x;
    string com;
    scanf("%d",&n);
    
    for ( i = 0; i < n; i++ ) {
        cin >> com;
        if ( com[0] == 'f'){

    scanf("%d", &x);
    Node *t = find(root, x);
            if ( t != NIL ) printf("yes\n");
     else printf("no\n");
        }else if ( com == "insert" ) {
        scanf("%d", &x);
        insert(x);
    }else if ( com == "print" ) {
        inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
            
        }
    return 0;
        
    }


Measured memory_bytes: 22072
#include <stdio.h>

int main(void) {
	char str[11];
	int ans[10];
	int i, j;
	while (scanf("%s", str) != EOF) {
		for (i = 0; i < 10; i++)
			ans[i] = str[i] - '0';
		for (i = 9; i > 0; i--) {
			for (j = 0; j < i; j++) {
				ans[j] = (ans[j] + ans[j+1]) % 10;
			}
		}
		printf("%d\n", ans[0]);
	}
	return 0;
}

Measured memory_bytes: 540
n = gets.chomp.to_i
alist = gets.chomp.split.collect{ |item| item.to_i}

llist = []
rlist = []
def gcd(a,b)
  return a if b == 0
  gcd(b, a) if b > a
  return b if (r = a % b).zero?
  gcd(b, r)
end
llist[0] = 0
rlist[n+1] = 0
n.times do |nn|
  llist[nn+1] = gcd(llist[nn],alist[nn])
  rlist[n-nn] = gcd(rlist[n-nn+1],alist[n-nn-1])
end
mlist = []
n.times do |nn|
  mlist[nn] = gcd(llist[nn],rlist[nn+2])
end
puts mlist.max

Measured memory_bytes: 12116
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
a,b,c,d=map(int,input().split())

e=0
f=0

while a>0:
	a-=d
	e+=1
	
while c>0:
	c-=b
	f+=1
	
if e>=f:
	print("Yes")
else:
	print("No")
	

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

int f(int x) { return x*x; }

int main() {
    int d;
    while (cin >> d) {
        int area = 0;
        for (int i = 1; i != 600/d; ++i) {
            area += d * f(i*d);
        }
        cout << area << endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int INF = 1e9;
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()
{
    
    //「dp[ i ] := 最初の i 日間での最適解」の形の DP 
    //dp[ i + 1 ][ j ] := i 日目までの活動履歴のうち、最終日である i 日目には活動 j (0: A, 1: B, 2: C) を選んだ場合の、得られる幸福度の最大値

    long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

    // DP テーブル
    long long dp[100010][3];
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    // 初期化は既に 0 に初期化される
    for(int i=0;i<N+10;i++){
    	for(int j=0;j<3;j++)
    	{
       	 	dp[i][j]=0;
    	}
	}

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if(j!=k)
                {
                    dp[i+1][k]=max(dp[i+1][k],dp[i][j]+a[i][k]);
                }
            }
        }
    }

    // 答え
    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4992
n = int(input())
l = [int(i) for i in input().split()]
l = sorted(l)
# 大きいものは大きいもの同士でペアを組んだ方がよい
# a>b>c>dで, 「b+d>c+d」より証明完了
count = 0
# print(l)
for i in range(n):
    count += l[i*2]
    # print(i)
print("{}".format(count))

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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int h, w;

char a[101][101];

bool lin[101], col[101];

void read() {
  cin >> h >> w;
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j) {
      cin >> a[i][j];
      if (a[i][j] == '#') {
        lin[i] = 1;
        col[j] = 1;
      }
    }
}

void solve() {
  for(int i = 0; i < h; ++i) {
    if (!lin[i])
      continue;
    for(int j = 0; j < w; ++j) {
      if (!col[j])
      continue;
      cout << a[i][j];
    }
    cout << "\n";
  }
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  //cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vi v(n, 0);
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		v[a - 1]++;
		v[b - 1]++;
	}
	REP(i, n) {
		cout << v[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <climits>

using namespace std;

#define MAX_V 20

int d[MAX_V][MAX_V];
int V;

void wf(){
  for(int k=0;k<V;k++)
    for(int i=0;i<V;i++)
      for(int j=0;j<V;j++)
	d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}


int main(){
  int m;
  cin>>V>>m;

  for(int i=0;i<V;i++){
    for(int j=0;j<V;j++){
      d[i][j]=100000;
    }
    d[i][i]=0;
  }

  int a,b,c,e;
  char yomisute;
  for(int i=0;i<m;i++){
    cin>>a>>yomisute>>b>>yomisute>>c>>yomisute>>e;
    --a;--b;
    d[a][b]=c;
    d[b][a]=e;
  }
  
  wf();


  cin>>a>>yomisute>>b>>yomisute>>c>>yomisute>>e;
  int money=0;

  a--;b--;
  money=d[a][b]+d[b][a];
  cout<<c-e-money<<endl;
}

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

int main()
{
    int n;
    long long int a[100010];
    long long int ans = 0;

    cin >> n;

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

    sort(a, a+n);

    for (int i = 0; i < n; i++) {
        if (i == n-i) {
            ans += a[i]-a[i-1];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
ans=0
N.times do
    l,r=get_i
    ans+=r-l+1
end
puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <string>
using namespace std;
#define MAX 100001

int odd[MAX];
int even[MAX];

int main() {
    for(int i=0; i<MAX; i++) odd[i]=0, even[i]=0;

    int n, a, b;
    cin >> n;
    for(int i=0; i<n; i+=2) {
        cin >> a >> b;
        even[a]++;
        odd[b]++;
    }

    int ef=-1, es=-1, of=-1, os=-1, efn=-1, esn=-1, ofn=-1, osn=-1;
    for(int i=0; i<MAX; i++) {
        if(ef<even[i]) {
            es = ef;
            esn = efn;
            ef = even[i];
            efn = i;
        } else if(es<even[i]) {
            es = even[i];
            esn = i;
        }
        if(of<odd[i]) {
            os = of;
            osn = ofn;
            of = odd[i];
            ofn = i;
        } else if(os<odd[i]) {
            os = odd[i];
            osn = i;
        }
    }

    if(efn==ofn) {
        cout << min(n-es-of, n-ef-os) << endl;
    } else {
        cout << n-ef-of << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<limits>
#include<iomanip>
#include<set>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 10000000000LL //long long int専用
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
	int x, y;
	cin >> x >> y;

	cout << x + (y / 2) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] seat = new int[N*2]; 
		int people = 0;
		for (int i = 0; i < seat.length; i++) {
			seat[i] = sc.nextInt();
			if (i % 2 == 1) {
				people = people + seat[i] - seat[i - 1] + 1;
			}
		}
		System.out.println(people);
	}
}

Measured memory_bytes: 24532
# https://atcoder.jp/contests/abc118/tasks/abc118_b
n, m = [int(x) for x in input().split()]
a = []
r = set(_ for _ in range(1, m + 1))
for _ in range(n):
    k = [int(x) for x in input().split()][1:]
    a.append(k)
for t in a:
    r &= set(t)
print(len(r))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;


int main(){
  int h,w,d;
  cin >> h >> w >> d;
  vector<P> a(100000);
  rep(i,h)rep(j,w){
    int k; cin >> k;
    a[k].F=j+1;
    a[k].S=i+1;
  }

  vector<ll> sum(100000,0);
  for(int i=d+1; i<=h*w; i++){
    sum[i] = sum[i-d] + abs(a[i].F-a[i-d].F) + abs(a[i].S-a[i-d].S);
  }


  int q;
  cin >> q;
  rep(aaa,q){
    int l,r; cin>>l>>r;
    cout << sum[r]-sum[l] << endl;
  }
  return 0;
}


Measured memory_bytes: 2688
module Main where
import Data.List
getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  k:t:_ <- getInts
  as <- getInts
  print $ solve k t as
  return ()

solve k t xs
  | t == 1    = head xs - 1
  | otherwise = if d < 0
                then 0
                else d - 1
  where
    m = maximum xs
    s = sum xs
    d = m - (s - m)


Measured memory_bytes: 1020
import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
      Scanner scan = new Scanner(System.in);
      int a = scan.nextInt();
      int b = scan.nextInt();
      int c = scan.nextInt();

      if (b < a) {
         a = a + b;
         b = a - b;
         a = a - b;
      }

      if (c < a) {
         a = a + c;
         c = a - c;
         a = a - c;
      }

      if (c < b) {
         b = b + c;
         c = b - c;
         b = b - c;
      }

      System.out.println(a + " " + b + " " + c);

   }
}



Measured memory_bytes: 26440
/*
    author: masab hasnain
*/

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

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

    long long  n, m;
    cin >> n >> m;

    long long tot = 0;
    while(m--){
        long long k;
        cin >> k;
        tot += k;
    }
    if(tot> n){
        cout << -1 << endl;
    }
    else
        cout << n - tot << endl;
}


Measured memory_bytes: 3612
class Point():
	def __init__(self, x, y):
		self.x = x
		self.y = y
	

output_list = []


init_point = map(float, raw_input().split())

p0 = Point(init_point[0], init_point[1])
p1 = Point(init_point[2], init_point[3])


q = int(raw_input())
datalist = [map(float, raw_input().split()) for i in range(q)]


#p0--p1 : y=ax+b
#p2--t  : y=cx+d

if (p0.x - p1.x) == 0:
	for data in datalist:
		p2 = Point(data[0], data[1])
		output_list.append( (p0.x, p2.y) )

elif (p0.y - p1.y) == 0:
	for data in datalist:
		p2 = Point(data[0], data[1])
		output_list.append( (p2.x, p0.y) )
		
else:
	a = (p0.y - p1.y) / (p0.x - p1.x)
	c = -1/a
	b = p0.y - a*p0.x
	
	for data in datalist:
		p2 = Point(data[0], data[1])
		
		d = p2.y - c*p2.x
		
		X = (-b+d) / (a-c)
		Y = a*X + b
		
		output_list.append( (X,Y) )
		
for x, y in output_list:
	print "%.10f %.10f" % (x, y)
	

Measured memory_bytes: 4432
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int sol = 0;
    for (int i = 1; i <= n; ++i)
    {
        int dig = 0;
        int j = i;
        while (j)
            dig++, j /= 10;
        sol += dig%2;
    }
    cout << sol;
}


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

#define int long long

signed main(){
    int n, x;
    cin >> n >> x;
    int ans = n;

    int a = n-x;
    int b = x;
    while(1){
        ans += (a/b) * b * 2;
        a %= b;
        if(a == 0){
            ans -= b;
            break;
        }
        int tmp = b;
        b = a;
        a = tmp;
    }

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

Measured memory_bytes: 256
image_lines, template_lines = gets.chomp.split(" ").map(&:to_i)
image = []
template = []
image_lines.times do
  image << gets.chomp
end
template_lines.times do
  template << gets.chomp
end

found = false
catch(:out) do
  image.each_with_index do |iline, idx|
    break if idx + template_lines > image_lines

    if a = iline.index(template[0])
      # puts "aaa #{a}"
      found = true
      template.each_with_index do |tline, tidx| # 2行目以降のみ
        next if tidx == 0
        # next if image[idx + tidx][a, tline.size] == tline[tidx]
        if image[idx + tidx][a, tline.size] == tline
          # puts "tru"
          next
        end
        # puts "fals"
        # puts image[idx + tidx][a, tline.size], tline
        found = false
        break
      end

      throw :out if found
    end
  end
end

puts found ? "Yes" : "No"


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);
// priority_queue<ll, vector<ll>, greater<ll>> pq;

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


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ios_base::sync_with_stdio(0);
	int n;
	scanf("%d",&n);
	int a[n];
	int co=0;
	for(int i=0;i<n;i++)
	 scanf("%d",&a[i]);
	 
	 for(int i=0;i<n-1;i++)
	 {
	 	for(int j=0;j<n-i-1;j++)
	 	{
	 		if(a[j]>a[j+1])
	 		{
	 			swap(a[j],a[j+1]);
	 			co++;
	 		}
	 	}
	 }
	 
	 printf("%d",a[0]);
	 for(int i=1;i<n;i++)
	 printf(" %d",a[i]);
	 printf("\n%d\n",co);
	return 0;
}

Measured memory_bytes: 3220
/*
* @author:  codancer
* @createTime:  2020-07-05, 19:51:53
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
int main(){
	int n;
	cin>>n;
	if(n%1000==0){
		cout<<0<<endl;
	}else{
		cout<<(n/1000+1)*1000-n<<endl;
	}
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000001


int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector<string> A(N),B(M);
	
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	for(int i=0;i<M;i++){
		cin>>B[i];
	}
	
	for(int i=0;i<N-M+1;i++){
		for(int j=0;j<N-M+1;j++){
			bool f = true;
			for(int k=0;k<M;k++){
				if(B[k]!=A[i+k].substr(j,M)){
					f=false;
					break;
				}
			}
			if(f){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	
	cout<<"No"<<endl;
	
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

typedef long long llong;

int n, k;

llong T[MAX];
 
int allCheck(llong P);
int allSolve();
 
int main(){

  int i;

  scanf("%d%d",&n,&k);

  for(i = 0;i < n;i ++)
    {
      scanf("%d",&T[i]);
    }
  llong ans = allSolve();

  printf("%d\n",ans);
 
  return 0;
}

int allCheck(llong P){

  int i = 0, j;

  for(j = 0;j < k;j ++)
    {
      llong s = 0;

      while(s + T[i] <= P)
	{
	  s += T[i];
	  i ++;
	  if(i == n) return n;
	}
    }
  return i;
}
 
int allSolve(){

  llong left = 0;
  llong right = 100000 * 10000;
  llong mid;
  int v;

  while(right - left > 1){

    mid = (left + right) / 2;

    v = allCheck(mid);

    if(v >= n){
      right = mid;
    }
    
    else left = mid;
  }
 
  return right;
}

Measured memory_bytes: 1376
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, m;
    cin>>n>>m;
    vl as(n);
    rep(i, m) {
        ll v1, v2;
        cin>>v1>>v2; v1--; v2--;
        if (v1 == 0) as[v2]++;
        else if (v2 == 0) as[v1]++;
        else {
            as[v1]++;
            as[v2]++;
        }
    }
    rep(i, n) {
        if (as[i] % 2) {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int a, b, c;
    cin >> a >> b >> c;

    cout << a * b / 2 << endl;
}


Measured memory_bytes: 256
//template
import java.util.*;
import java.util.stream.*;
import java.io.*;
public class Main{
	static BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	
	private static final int HUNDRED = 100;
	public static void main(String[] args) throws IOException{
		
		Scanner scanner=new Scanner(System.in);
		int n=scanner.nextInt(),k=scanner.nextInt();
		IntStream.range(0, n).forEach(i->scanner.nextInt());
		out.append((n+k-3)/(k-1)+"");
		
		out.flush();
		in.close();
		out.close();
	}
	private static int modulo(int S, int N) { return ((S) & (N - 1)); } // returns S % N, where N is a power of 2
	private static int isPowerOfTwo(int S) { return (S & (S - 1)) == 0 ? 1 : 0; }
	private static int[] readInts() throws IOException {
		return Stream.of(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
	}
	private static int readInt() throws IOException {
		return Integer.parseInt(in.readLine());
	}
	private static long[] readLongs() throws IOException {
		return Stream.of(in.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
	}
	private static long readLong() throws IOException {
		return Long.parseLong(in.readLine());
	}
	 
}


Measured memory_bytes: 59456
from itertools import accumulate

n, q = map(int, input().split())
s = input()

lr = [list(map(int, input().split())) for _ in range(q)]

p = [0] * n
for i in range(1, n):
  pp = 0
  if s[i-1:i+1] == "AC":
    pp = 1
  p[i] = pp
  
p = [0] + list(accumulate(p))

for e in lr:
  print(p[e[1]] - p[e[0]])

Measured memory_bytes: 33152
using System;

public class Test
{
	public static void Main()
	{
            double pai = 3.141592653589;
            double r=0;
            double ensyuu = 0, menseki = 0;
            r = double.Parse(Console.ReadLine());
            menseki = r * r * pai;
            ensyuu = r * 2 * pai;
            Console.WriteLine("{0:0.000000} {1:0.000000}",menseki,ensyuu);
	}
}

Measured memory_bytes: 9252
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]); var wmax = int.Parse(line[1]);
        var vaL = new int[n + 1]; var w = new int[n + 1];
        var dp = new int[n + 1, wmax + 1];
        DpSet(dp, vaL, w);
        for (int i = 0; i < n; i++)
            for (int j = 0; j <= wmax; j++)
            {
                if (j < w[i]) dp[i + 1, j] = dp[i, j];
                else dp[i + 1, j] = Math.Max(dp[i, j], dp[i, j - w[i]] + vaL[i]);
            }
        Console.WriteLine(dp[n, wmax]);
    }
    public static void DpSet(int[,] dp, int[] vaL, int[] w)
    {
        for (int i = 0; i < vaL.Length - 1; i++)
        {
            string[] line2 = Console.ReadLine().Trim().Split(' ');
            vaL[i] = int.Parse(line2[0]);
            w[i] = int.Parse(line2[1]);
        }
    }
}

Measured memory_bytes: 13116
import java.io.*;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        int N = in.nextInt();
        int K = in.nextInt();
        int X = in.nextInt();
        int Y = in.nextInt();


        if (K > N) {
            System.out.println(N * X);
        } else {
            int sumX = K * X;
            int sumY = (N - K) * Y;
            System.out.println(sumX + sumY);
        }

    }


    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,sum;
int main()
{
	cin>>n>>a>>b;
	if(n>1&&b>=a) sum=(n-2)*(b-a)+1;
	if(n==1&&b==a) sum=1;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

typedef long long ll;

int main()
{
    string s;
    cin >> s;
    int cnt = 0;
    for(auto c : s){
        if(c == '1') cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

int x[5];

void input(){
  for (int i=0;i<5;i++){
    cin >> x[i];
  }
}

int main(){
  input();
  int ans=0;
  for(int i=0;i<5;i++){
    if(x[i]==0){
      cout << i+1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define X first
#define Y second
 
using namespace std;
typedef long long llint;
 
const int maxn = 2e5+10;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;

int n, m;
vector< int > graph[maxn];
bool bio[maxn];

int dfs(int x) {
	bio[x] = true;
	int out = 1;
	for (int i = 0; i < graph[x].size(); i++) {
		int tren = graph[x][i];
		if (!bio[tren]) out += dfs(tren);
	}
	return out;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	memset(bio, false, sizeof bio);
	int sol = 0;
	for (int i = 1; i <= n; i++) {
		if (!bio[i]) sol = max(sol, dfs(i));
	}
	printf("%d", sol);
	return 0;
}

Measured memory_bytes: 24204
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M = (int)2e5+5;
const int mod = (int)1e9+7;

void solve()
{
    int x, k, d;
    cin>>x>>k>>d;
    x = abs(x);
    int n = x/d;
    if(n >= k)
    {
    	cout<<x-k*d<<endl;
    	return;
    }
    x = x-n*d;
    k -= n;
    if(k%2) cout<<abs(x-d)<<endl;
    else cout<<x<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    // cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3684
while True:
    m,f,r=map(int,input().split())
    if m==-1 and f==-1 and r==-1:
        break
    if m==-1 or f==-1:
        print('F')
    elif m+f>=80:
        print('A')
    elif 65<=m+f<80:
        print('B')
    elif 50<=m+f<65:
        print('C')
    elif 30<=m+f<50:
        if r>=50:
            print('C')
        else:
            print('D')
    else:
        print('F')

Measured memory_bytes: 7580
#include<iostream>
#include<string>
#include<vector>
#include <cmath>
using namespace std;
int main() {
    int A, B;
    cin >> A >> B;
    if(A%3==0 || B%3==0 || (A+B)%3==0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
}

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

string a,b="CF";
int al,bl;
int main()
{
    getline(cin,a);
    al=a.length();
    for(int i=0;i<al;i++)
        if(a[i]==b[bl])
        {
            bl++;
            if(bl==2)
                break;
        }
    if(bl==2) 
        cout<<"Yes";
    else 
        cout<<"No";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
# p (0..6).to_a.map{|j| [6 ** j, 9 ** j] }.flatten.uniq
a = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 59049, 46656, 531441]

m, dp = gets.to_s.to_i, [0]
(1..m).each {|i|
  cans = a.select {|j| i - j >= 0 }.map{|j| i - j }
  t = 10**18
  cans.each{|c| t = dp[c] if t > dp[c] }
  dp.push(t + 1)
}
p dp.last

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

class Cube{
    public:
        int f[6];
        Cube(){}
        void roll_x(){roll(0,1,5,4);}
        void roll_y(){roll(0,2,5,3);}
        void roll_z(){roll(1,2,4,3);}
        void roll(int i,int j,int k,int l){
            int t=f[i];
            f[i]=f[j];
            f[j]=f[k];
            f[k]=f[l];
            f[l]=t;
        }
};

bool eq(Cube c1,Cube c2){
    for(int i=0;i<6;i++){
        if(c1.f[i]!=c2.f[i])return false;
    }
    return true;
}

bool equal(Cube c1,Cube c2){
    for(int i=0;i<6;i++){
        for(int j=0;j<4;j++){
            if(eq(c1,c2)) return true;
            c1.roll_z();
        }
        if(i%2==0)c1.roll_y();
        else c1.roll_x();
    }
    return false;
}
    int n;
    
    Cube C[100];
bool check(){
 for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(equal(C[i],C[j])){
                    return false;
             }
        }
    }
  return true;
}


int main(){
    
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<6;j++) cin>>C[i].f[j];
    }

     if(check())cout<<"Yes"<<endl;
     else cout<<"No"<<endl;
    
    }


    

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
	int a, b;
  	cin >> a >> b;
 	cout << max({a+b, a-b, a*b}) << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


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

int main() {
  int r, c;
  cin >> r >> c;
  int a[110][110] = {};

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
    }
  }
  //縦
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      a[i][c] += a[i][j];
    }
  }

  //横
  for (int j = 0; j <= c; j++) {
    for (int i = 0; i < r; i++) {
      a[r][j] += a[i][j];
    }
  }


  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if(j == c){
        cout << a[i][j];
        continue;
      }
      cout << a[i][j] << " ";

    }
    cout << endl;
  }

}



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

namespace ITP1_5_D
{
    class Program
    {
        static void Main(string[] args)
        {

            // 与えられた整数3≤n≤10000に対し以下を行う
            // ① 3からnの中に含まれる整数は3で割り切れるか？
            // ② 3からnの中に含まれる整数は3を含むか？
            // ③ ①または②に当てはまる整数を昇順に出力する

            int n1 = int.Parse(Console.ReadLine());

            int i = 0;

            while (true)
            {
                if (n1 < 3 || 10000 < n1)                       // nが3以下or10000以上の時 処理を終了する
                {
                    break;
                }

                else
                {
                    for (i = 1; i <= n1; i++)
                    {
                        int n2 = i;                             // int n2　1からn1までの整数が入る変数
                        if (n2 % 3 == 0)                        // n2が3で割り切れるとき、n2を表示させる
                        {
                            Console.Write(" " + n2);
                        }
                        else if (n2.ToString().Contains("3"))   //文字列n2に"3"が含まれるとき、n2を表示させる。
                        {
                            Console.Write(" " + n2);
                        }
                        else
                        {

                        }
                    }
                    
                    break;
                }
            }
            Console.WriteLine();
        }
    }
}



Measured memory_bytes: 15904
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
#define ALL(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;++i)

int main(){
  ll n,m;
  cin >>n >>m;
  ll res=m,ans=0;

  ll a,b;

  vector<pair<ll,ll> >p;
  rep(i,n){
    cin >> a >> b;
    p.push_back(make_pair(a,b));
  }
  sort(ALL(p));
  for(auto itr=p.begin();itr!=p.end();itr++){
    if(res>itr->second){
      res-=itr->second;
      ans+=(itr->first)*(itr->second);
    }else{
      ans+=(itr->first)*res;
      break;
    }
  }

  cout << ans <<endl;

}


Measured memory_bytes: 2420
import java.util.*;

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

		int n = sc.nextInt();
		int weights[] = new int[n];

		int group2 = 0;

		for(int i = 0; i < n; i++) {
			weights[i] = sc.nextInt();
			group2 += weights[i];
		}

		int group1 = 0;
		int t = 0;

		while(group1 < group2) {
			group1 += weights[t];
			group2 -= weights[t];
			t++;
		}

		if(Math.abs(group2 - group1) > Math.abs((group2 + weights[t - 1]) - (group1 - weights[t - 1]))) {
			group1 -= weights[t - 1];
			group2 += weights[t - 1];
		}

		System.out.println(Math.abs(group2 - group1));
	}
}


Measured memory_bytes: 23252