akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

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

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

LL count_node = 1;
LL node[500002] = {0};
vector<vector<PLL>> link(500002);

void f(LL i){
    if(node[i]!=-1)return;
    count_node++;
    node[i] = 1;

    EACH(itr, link[i]){
        f(itr->first);
    }
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i,500002)node[i]=-1;

    int n,m;
    cin>>n>>m;
    REP(i,m){
        int x,y,z;
        cin>>x>>y>>z;
        link[x].PB(MP(y,z));
        link[y].PB(MP(x,z));
    }
    LL ans = 0;
    REP(i,n){
        count_node = 0;
        f(i+1);
        if(count_node != 0)ans += 1;
    }
    PUTS(ans);
}

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

int main() {
    int h, w;
    cin >> h >> w;
    
    vector<vector<char>> a(h, vector<char>(w));
    vector<vector<char>> b(h+2, vector<char>(w+2));

    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            cin >> a.at(i).at(j);
        }
    }

    for (int i=0; i<h+2; i++) {
        for (int j=0; j<w+2; j++) {
            b.at(i).at(j) = '#';
        }
    }

    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            b.at(i+1).at(j+1) = a.at(i).at(j);
        }
    }

    for (int i=0; i<h+2; i++) {
        for (int j=0; j<w+2; j++) {
            cout << b.at(i).at(j);
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  ll n,m,a[1010],b[1010],c[110][110]={},d[110][110]={},ans=0;
  cin>>n>>m;
  Fr(i,n) Fr(j,n) if(i!=j) d[i][j]=10000;
  Fr(i,m){
    cin>>a[i]>>b[i];
    cin>>c[a[i]][b[i]];
    c[b[i]][a[i]]=c[a[i]][b[i]];
    d[a[i]][b[i]]=c[a[i]][b[i]];
    d[b[i]][a[i]]=c[a[i]][b[i]];
  }
  Fr(k,n) Fr(i,n) Fr(j,n) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
  Fr(i,m) if(c[a[i]][b[i]]>d[a[i]][b[i]]) ans++;
  cout<<ans<<endl;
}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define vi vector<int>
#define vl vector<long long>
#define sz size()
#define x first
#define y second
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;
ll a[100100];
ll n, A, B;

bool check(ll k) {
	ll cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(k * B >= a[i]) continue;
		ll cur = (a[i] - k * B)/(A - B);
		cnt += cur;
		if((a[i] - k * B) % (A - B)) cnt++;
	}

	return cnt <= k;
}

int main() {
		
	cin >> n >> A >> B;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + n + 1);
	reverse(a + 1, a + n + 1);
	
	
	ll L = 0, R = (ll)1e9;

	while(L < R) {
		ll mid = (L + R)/2;
		if(check(mid)) {
			R = mid;
		} else {
			L = mid + 1;
		}
	}
	
	cout << R;

	return 0;
}

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

using namespace std;

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

Node *root, *NIL;

void insert(int key) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = key;
  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 find(int k) {
  Node *node = root;
  while (node != NIL) {
    if (k == node->key) {
      printf("yes\n");
      return;
    }
    if (k < node->key) {
      node = node->left;
    } else if (k > node->key) {
      node = node->right;
    }
  }
  printf("no\n");
  return;
}

void inorder(Node *node) {
  if (node == NIL) return;
  inorder(node->left);
  printf(" %d", node->key);
  inorder(node->right);
}
void preorder(Node *node) {
  if (node == NIL) return;
  printf(" %d", node->key);
  preorder(node->left);
  preorder(node->right);
}

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

  for (int i = 0; i < n; i++) {
    string s; int key;
    cin >> s;
    if (s == "insert") {
      cin >> key;
      insert(key);
    } else if (s == "find") {
      cin >> key;
      find(key);
    } else if (s == "print") {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 21964
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		//System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] vect1 = new int[n];
		int[] vect2 = new int[n];
		double keisan = 0.0;
		for(int i=0;i<n; i++){
			vect1[i] = scan.nextInt();
		}
		for(int i=0;i<n; i++){
			vect2[i] = scan.nextInt();
		}

		for(int i=0;i<n; i++){
			double zet = 0;
			zet = vect1[i] - vect2[i];
			zet = Math.abs(zet);
			zet = Math.pow(zet,1);
			keisan += zet;
		}
		keisan = Math.pow(keisan, (1.0/1.0));
		System.out.println(keisan);
		keisan = 0.0;

		for(int i=0;i<n; i++){
			double zet = 0;
			zet = vect1[i] - vect2[i];
			zet = Math.abs(zet);
			zet = Math.pow(zet,2);
			keisan += zet;
		}
		keisan = Math.pow(keisan, (1.0/2.0));
		System.out.println(keisan);
		keisan = 0.0;

		for(int i=0;i<n; i++){
			double zet = 0;
			zet = vect1[i] - vect2[i];
			zet = Math.abs(zet);
			zet = Math.pow(zet,3);
			keisan += zet;
		}
		keisan = Math.pow(keisan, (1.0/3.0));
		System.out.println(keisan);
		keisan = 0.0;

		for(int i=0;i<n; i++){
			double zet = 0;
			zet = vect1[i] - vect2[i];
			zet = Math.abs(zet);
			if(zet>keisan){
				keisan = zet;
			}
			
		}
		System.out.println(keisan);
		keisan = 0.0;
	}
}

Measured memory_bytes: 26492
#include <iostream>
#include <map>
#define For(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
    int N, M;
    map<string, int> m;

    cin >> N;
    For(i, N) {
        string temp;
        cin >> temp;
        if (m.find(temp) == m.end()) {
            m.insert(make_pair(temp, 1));
        } else {
            int value = m.at(temp);
            m.erase(temp);
            m.insert(make_pair(temp, ++value));
        }
    }

    cin >> M;
    For(i, M) {
        string temp;
        cin >> temp;
        if (m.find(temp) == m.end()) {
            m.insert(make_pair(temp, -1));
        } else {
            int value = m.at(temp);
            m.erase(temp);
            m.insert(make_pair(temp, --value));
        }
    }

    int result = 0;
    for (auto i : m) {
        if (i.second > result) result = i.second;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int count=0;
  
  if(s[0]=='A'){
    if(s[1]>='a'&&s[1]<='z'&&s[s.size()-1]>='a'&&s[s.size()-1]<='z'){
      for(int i=2;i<s.size()-1;i++){
        if(s[i]=='C'){
          count++;
        }
      }
    }
  }
  if(count==1){
      cout << "AC" << endl;
    }else{
      cout << "WA" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++){
		cin>>A[i];
		ans-=A[i]*A[i];
		k+=A[i];
	}
	k=k*k;
	ans+=k;
	cout<<ans/2<<'\n';
	
	return 0;
}



Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{   long long n,i,ans=0,cnt=0,lo,hi,mid;
    cin>>n;
    
       cnt=0;
        for(i=2;i*i<=n;i++)
        {  cnt=0;
            while(n%i==0)
           { n=n/i;cnt++;}
        lo=0;
        hi=1e5;
        while(lo<hi)
        {   mid=lo+(hi-lo+1)/2;
            //cout<<lo<<"lo "<<mid<<"mid "<<hi<<"hi ";
            if((mid*(mid+1))/2>cnt){hi=mid-1;}
            else{lo=mid;}
        }
        ans+=lo;
        }
    if(n>2){ans+=1;}
    cout<<ans;
    return 0;
}

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

int main(){
  int A,B,C,D,E,F;
  cin >> A >> B >> C >> D >> E >> F;
  
  int w,s;
  int ans_ws = 0;
  int ans_s = 0;
  
  for(int a=0;100*A*a<=F;a++){
    for(int b=0;100*A*a+100*B*b<=F;b++){
      for(int c=0;100*A*a+100*B*b+C*c<=F;c++){
        for(int d=0;100*A*a+100*B*b+C*c+D*d<=F;d++){
          w = 100*A*a + 100*B*b;
          s = C*c + D*d;
          if(E*w >= s*100 && s*ans_ws >= (w+s)*ans_s){
            ans_ws = w + s;
            ans_s = s; 
          }
        }
      }
    }
  }
  
  cout << ans_ws << " " << ans_s << "\n"; 
}

Measured memory_bytes: 256
"""
C - Energy Drink Collector
"""


def solve():
    N, M = map(int, input().split())
    AB = [list(map(int, input().split())) for n in range(N)]
    AB.sort()
    ans = 0
    for a, b in AB:
        if M > b:
            ans += a * b
            M -= b
        else:
            ans += a * M
            break
    print(ans)


if __name__ == '__main__':
    solve()


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

int main() {
    int N;
    cin >> N;
    vector<string> blue(N);
    for(int i = 0; i < N; i++) cin >> blue.at(i);
    int M;
    cin >> M;
    vector<string> red(M);
    for(int i = 0; i < M; i++) cin >> red.at(i);

    int ans = 0;
    for(int i = 0; i < N; i++){
        int score = 0;
        for(int j = 0; j < N; j++) if(blue.at(i) == blue.at(j)) score++;
        for(int j = 0; j < M; j++) if(blue.at(i) == red.at(j)) score--;
        ans = max(ans, score);
    }
    cout << ans << endl;

    
}

Measured memory_bytes: 256
def main():
    from collections import deque
    import sys
    input = sys.stdin.readline

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

    g = tuple(set() for _ in range(N * 3))
    for _ in range(M):
        u, v = (int(x) - 1 for x in input().split())
        g[u].add(v + N)
        g[u + N].add(v + N + N)
        g[u + N + N].add(v)

    S, T = (int(x) - 1 for x in input().split())

    dist = [-1] * (N * 3)
    dist[S] = 0

    dq = deque()
    dq.append(S)
    while dq:
        v = dq.popleft()
        for u in g[v]:
            if ~dist[u]: continue
            dist[u] = dist[v] + 1
            dq.append(u)

    if dist[T] % 3:
        print(-1)
        return

    print(dist[T] // 3)


if __name__ == '__main__':
    main()


Measured memory_bytes: 99496
#include<iostream> 
#include<vector> 
#include<algorithm> 
#include<iomanip> 
#include<stack> 
#include<unordered_map>
#include<queue> 
#include<map> 
#include<climits>
#include<set> 
#include<string> 
//#include<time.h>
//#include<bits/stdc++.h> 
using namespace std; 
#define lld long long int 
#define eb emplace_back
//to insert pair use eb
#define mp make_pair
#define fi first
#define se second
#define pb push_back

#define X 1000000007
#define Y 998244353
#define E4 10000
#define E5 100000
#define E6 1000000
#define inf 1001001001
#define longinf 2001001001001001001
#define pi 3.1415926535

# define rec2(i,a,b) for(lld i=a;i<b;i++) 
#define rec(i,n) for(lld i=0;i<n;i++)
#define rev(i,a,b) for(lld i=b-1;i>=a;i--)
#define all(v) (v).begin(), (v).end()
#define large(v)  *max_element(all(v))
#define small(v)  *min_element(all(v)) 
#define v vector
const double EPS = 1e-6;

void google(int i)
{  cout<<"Case #"<<i<<":"; }

//prime sieve if needed 
//prime factors of number
lld prime[E6+1]; 
void sieve(lld n) 
{ rec(i,n+1) 
    prime[i]=1; 
   for(lld i=2;i*i<=n;i++) 
     { if(prime[i]!=1) 
          continue; 
         for(lld j=i*i;j<=n;j=j+i) 
          if(prime[i]==1)
           prime[j]=i; 
      }
}

lld gcd(lld a,lld b)
{
    if(a==0)
     return b; 
    return gcd(b%a,a); 
}

//fermat a^(m-2)%mod
lld binarymul(lld a,lld n,lld m)
{  lld res=1; 
 while(n) 
  { if(n%2) 
      { res=(res*a)%m; 
         n--; 
      } 
     a=(a*a)%m; 
     n/=2; 
  }
  return res; 
}
/*
void complexity(time_t end,time_t start)
{ 
  double taken = double(end - start); 
    cout<<"Time : "; 
    cout<<fixed<<taken<<setprecision(8);         cout<<" sec "<<endl;
}
*/
void contest(); 
int main()
{   
    /*
    time_t start, end; 
    time(&start); 
    */
   ios_base::sync_with_stdio(false); 
   cin.tie(0);
     #ifdef PUNEET_GOEL
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif
   //sieve(E6); 
    lld t=1; 
    rec(i,t) 
    {
     //google(i+1); 
      contest(); 
      cout<<endl; 
    }
    /*
     time(&end); 
    complexity(end,start);
    */
	return 0;
}

void contest()
{ 
  lld x,k,d; 
  cin>>x>>k>>d; 
  if(x<0) 
   x=0-x; 
   lld h=x/d; 
   if(h>=k)
    x=x-k*d; 
   else 
    { 
      lld ans=x-h*d; 
      if((k-h)%2) 
       ans-=d; 
      if(ans<0) 
      ans=0-ans; 
      x=ans; 
    } 
    cout<<x; 
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans;

int main(void) {
    int N;
    cin >> N;
    int cnt = 0;
    bool ok = false;
    rep(i, 0, N) {
        int d1, d2;
        cin >> d1 >> d2;
        if (d1==d2) cnt++;
        else cnt = 0;
        if (cnt==3) ok = true;
    }


    
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}





Measured memory_bytes: 3628
// https://atcoder.jp/contests/abc042/tasks/abc042_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, L;
    cin >> N >> L;
    vector<string> v(N);
    REP(i, N) { cin >> v[i]; }
    sort(ALL(v));
    for (auto &x : v)
        cout << x;
    cout << "\n";

    return 0;
}


Measured memory_bytes: 256
A, B = gets.split.map(&:to_i)

A_lowerBound = (A.to_f/0.08).ceil
A_upperLimit = ((A.to_f + 1.0)/0.08).floor

B_lowerBound = (B.to_f/0.1).ceil
B_upperLimit = ((B.to_f + 1.0)/0.1).floor

if A_lowerBound >= B_upperLimit || A_upperLimit <= B_lowerBound then
  p -1
else
  p [A_lowerBound, B_lowerBound].max
end


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

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;

	int num1 = 10 * B;
	int num2 = 10 * (B + 1);

	for (int i = num1; i < num2; i++) {
		int num = i * 0.08;
		if (num == A) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;

}

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

int main()
{
  char s[101];
  int i,len, loop_num, hug;

  scanf("%s", &s);

  len = strlen(s);
  loop_num = len / 2;
  hug = 0;

  for (i = 0; i<loop_num; i++)
  {
    if (s[i] != s[len - 1 - i])
    {
       hug++;
    }
  }

  printf("%d",hug);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <list>

using namespace std;

int main(){

    int N, H;
    cin >> N >> H;
    list<int> b(N);
    int a = 0;
    int i;
    for(i = 0; i < N; i++){
        int aa, bb;
        cin >> aa >> bb;
        b.push_back(bb);
        if(aa > a)a = aa;
    }
    b.sort();

    int h = H;
    int sum = 0;
    while(h > 0){
        if(a > b.back()){
            h = h - a;
        }else{
            h = h -b.back();
            b.pop_back();
        }
        sum ++;
    }
    cout << sum << endl;

    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  int res = 0;
  for (int i = 0; i < N/2; ++i) {
    if (S[i] != S[N-i-1]) ++res;
  }
  cout << res << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int w, h;
        cin >> w >> h;
        if(w == 0)
            return 0;

        vector<vector<int> > grid(h+1, vector<int>(w+2, 0));
        for(int i=0; i<h+1; ++i)
            grid[i][0] = grid[i][w+1] = 1;
        for(int i=0; i<h; ++i){
            for(int j=1; j<=w; ++j){
                cin >> grid[i][j];
            }
        }

        vector<vector<int> > num(h+1, vector<int>(w+2, 0));
        for(int i=1; i<=w; ++i){
            if(grid[0][i] == 0)
                num[0][i] = 1;
        }

        for(int y=0; y<h-1; ++y){
            for(int x=1; x<=w; ++x){
                if(grid[y][x] == 2){
                    if(grid[y+2][x] != 1)
                        num[y+2][x] += num[y][x];
                }else{
                    for(int dx=-1; dx<=1; ++dx){
                        if(grid[y+1][x+dx] == 1 || (grid[y+1][x+dx] == 2 && dx != 0))
                            continue;
                        num[y+1][x+dx] += num[y][x];
                    }
                }
            }
        }

        int ret = accumulate(num[h-1].begin(), num[h-1].end(), 0);
        ret += accumulate(num[h].begin(), num[h].end(), 0);
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, m, a;
    while (1)
    {
        cin >> n >> m >> a;
        if (n == 0)
            break;
        vector<P> v[1010];
        rep(i, m)
        {
            int h, p, q;
            ;
            cin >> h >> p >> q;
            v[h].push_back(P(p, q));
        }
        int now = a;
        for (int H = 1000; H >= 0; H--)
        {
            rep(j, v[H].size())
            {
                if (v[H][j].first == now)
                    now = v[H][j].second;
                else if (v[H][j].second == now)
                    now = v[H][j].first;
            }
        }
        cout << now << endl;
    }
}


Measured memory_bytes: 3164
#include<stdio.h>
int main()
{
  int n, a[100], i, j, minj, tmp, count = 0;
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      scanf("%d", &a[i]);
    }
  for(i = 0; i < n; i++)
    {
      minj = i;
      for(j = i; j < n; j++)
	{
	  if(a[j] < a[minj])
	    {
	      minj = j;
	    }
	}
      if(a[i] > a[minj])
	{
	  count++;
	}
      tmp = a[i];
      a[i] = a[minj];
      a[minj] = tmp;
    }
  for(i = 0; i < n - 1; i++)
    {
      printf("%d ", a[i]);
    }
  printf("%d\n", a[n-1]);
  printf("%d\n", count);
  return 0;
}



Measured memory_bytes: 2124
function main(input) {
    var i, j, A, ans=0
    var inputs = input.split("\n")
    var arg = inputs[0].split(" ").map((v)=>(parseInt(v)))
    //A=new Array(arg[0])
    A=[]
    for (i=0;i<arg[0];++i){
        A.push(inputs[i+1].split(" ").map((v)=>(parseInt(v))))
    }
    A.sort(function(a,b){return(a[0] - b[0])})
    i=0
    j=0
    while(arg[1]>0){
        var num = Math.min(arg[1], A[i][1])
        ans += A[i][0]*num
        arg[1] -= num
        i++
    }
    /*
    while(j<Number(arg[1])){
        if (arg[1]-j < A[i][1]){
            ans += Number(A[i][0])*(arg[1]-j)
            j = arg[1]
        }else{
            ans += Number(A[i][0])*Number(A[i][1])
            j += Number(A[i][1])
            A[i][1]=0
            i++
        }
    }*/
    console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 50208
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
const int maxn=100010;
int n;
int a[maxn];
map<int,int>mp;
void read(int& x){
	x=0;
	char c=getchar();
	while(c<'0' || c>'9') c=getchar();
	while(c>='0' && c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
}
int num[maxn];
int cnt;
int c[maxn][2];
int tot[maxn][2];
int ans;
int main(){
	read(n);
	for(int i=1;i<=n;i++) read(a[i]),num[i]=a[i];
	sort(num+1,num+1+n);
	cnt=unique(num+1,num+1+n)-num-1;
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(num+1,num+1+cnt,a[i])-num;
		c[a[i]][i&1]++;
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++){
		tot[a[i]][i&1]++;
	}
	for(int i=1;i<=n;i++){
		ans+=abs(c[i][0]-tot[i][0]);
	}
	printf("%d",ans/2);
	return 0;
}

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

int f(int a, int b){
    return max(to_string(a).size(), to_string(b).size());
}

int main(){
    ll n; cin >> n;
    int min_val = INT_MAX;
    for(int i=1; i<=(int)sqrt((double)n); i++){
        if(n%i != 0) continue;
        min_val = min(min_val, f(i, n/i));
    }
    cout << min_val << endl;
}


Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	vector<long long int> l;
	l.push_back(2);
	l.push_back(1);
	for (int i = 0; i < n; i++) {
		l.push_back(l[i] + l[i + 1]);


	}

	cout << l[n] << endl;
	return 0;
}

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

typedef complex<double> P;
const double pi = 3.1415926535;

int main()
{
	int N,D;
	while(cin >> N >> D, N||D)
	{
		P p(0,0),v(0,1);

		while(N--)
		{
			double L,R,T;
			cin >> L >> R >> T;

			if(L==R)
			{
				p += v*L*T * pi/180.0;
			}
			else
			{
				P c; double r;


				if(L*R==0)
				{
					if(abs(L)<abs(R))
					{
						r = 2*D;
						c = p + (r-D)*v*P(0,+1);

						p = c + (p-c)*polar(1.0, +R*T/r * pi/180);
						v = v        *polar(1.0, +R*T/r * pi/180);					
					}
					else
					{
						r = 2*D;
						c = p + (r-D)*v*P(0,-1);

						p = c + (p-c)*polar(1.0, -L*T/r * pi/180);
						v = v        *polar(1.0, -L*T/r * pi/180);					
					}
				}
				else if(L*R>0)
				{
					if(L<R)
					{
						r = L*(2*D)/(R-L);
						c = p + (r+D)*v*P(0,+1);

						p = c + (p-c)*polar(1.0, +L*T/r * pi/180);
						v = v        *polar(1.0, +L*T/r * pi/180);
					}
					else
					{
						r = R*(2*D)/abs(L-R);
						c = p + (r+D)*v*P(0,-1);

						p = c + (p-c)*polar(1.0, -R*T/r * pi/180);
						v = v        *polar(1.0, -R*T/r * pi/180);
					}
				}
				else
				{
					if(L<R)
					{
						r = D*(R+L)/(R-L);
						c = p + r*v*P(0,+1);

						r = abs(r);
						if(abs(L)<abs(R))
						{
							p = c + (p-c)*polar(1.0, +R*T/(D+r) * pi/180);
							v = v        *polar(1.0, +R*T/(D+r) * pi/180);
						}
						else
						{
							p = c + (p-c)*polar(1.0, +R*T/(D-r) * pi/180);
							v = v        *polar(1.0, +R*T/(D-r) * pi/180);						
						}
					}
					else
					{
						r = D*(R+L)/(R-L);
						c = p + r*v*P(0,+1);

						r = abs(r);

						if(abs(L)<abs(R))
						{
							p = c + (p-c)*polar(1.0, -L*T/(D-r) * pi/180);
							v = v        *polar(1.0, -L*T/(D-r) * pi/180);
						}
						else
						{
							p = c + (p-c)*polar(1.0, -L*T/(D+r) * pi/180);
							v = v        *polar(1.0, -L*T/(D+r) * pi/180);
						}
					}
				}
			}
		}

		cout.precision(8);
		cout.setf(ios::fixed);
		cout << p.real() << "\n" << p.imag() << "\n";
	}
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

typedef pair<int,int> Pi;
struct edge {int u, v; ll cost;};

vector<edge> es;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

// 計算量：O(ElogV)
ll kruskal(int V){

    sort(all(es), [&](const edge& e1,const edge& e2){
        return e1.cost < e2.cost;
    });

    UnionFind uf(V);

    ll res = 0;
    for(int i = 0; i < (int)es.size(); i++){
        edge e = es[i];
        if(!uf.issame(e.u,e.v)) {
            uf.merge(e.u,e.v);
            res += e.cost;
        }
    }
    return res;
}

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

    vector<pair<int,int>> X(N), Y(N);
    REP(i,N) {
        cin >> X[i].first >> Y[i].first;
        X[i].second = i;
        Y[i].second = i;
    }

    sort(all(X));
    REP(i, N - 1) es.push_back({X[i].second, X[i + 1].second, abs(X[i].first - X[i + 1].first)});

    sort(all(Y));
    REP(i, N - 1) es.push_back({Y[i].second, Y[i + 1].second, abs(Y[i].first - Y[i + 1].first)});

    cout << kruskal(N) << endl;;
}

Measured memory_bytes: 8048
program rainy_season
  implicit none
  character(3) :: s
  integer :: n
  read(*,*) s
  if (s == 'RRR') then
    n = 3
  else if (s == 'SRR' .or. s == 'RRS') then
    n = 2
  else if (s == 'SSS') then
    n = 0
  else
    n = 1
  end if
  write(*,'(i0)') n
end program rainy_season

Measured memory_bytes: 2864
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
int main(){
    int n,max_num = -1000001,min_num = 1000001,tmp;
    long long int sum = 0;
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%d",&tmp);
        sum += tmp;
        max_num = max(max_num,tmp);
        min_num = min(min_num,tmp);
    }
    printf("%d %d %lld\n",min_num,max_num,sum);
}


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

N, X, D = map(int, input().split())

if D == 0:
    ans = N+1 if X != 0 else 1
else:
    C = {}
    Que = {}
    for l in range(N+1):
        start = l*X//D + l*(l-1)//2
        end = start + l*(N-l)
        key = l*X%D
        if key in Que:
            Que[key].append((start, end))
            C[key] += [start, end, start+1, end+1, start-1, end-1]
        else:
            Que[key] = [(start, end)]
            C[key] = [start, end, start+1, end+1, start-1, end-1]


    ans = 0
    for key, List in C.items():
        ind_to_co = sorted(list(set(List)))
        co_to_ind = {a:i for i, a in enumerate(ind_to_co)}

        Imos = [0]*(len(ind_to_co)+1)
        for start, end in Que[key]:
            Imos[co_to_ind[start]] += 1
            Imos[co_to_ind[end+1]] -= 1

        for i in range(len(ind_to_co)-1):
            a = ind_to_co[i]; b = ind_to_co[i+1]
            Imos[i+1] += Imos[i]
            if Imos[i+1] > 0 and Imos[i] > 0:
                ans += b-a
            elif Imos[i] > 0:
                ans += 1
print(ans)

Measured memory_bytes: 161168
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split(' '))))

diff = A - (np.arange(N) + 1)
diff.sort()

if N % 2 == 0:
    median = (diff[N // 2] + diff[N // 2 - 1]) // 2
else:
    median = diff[N // 2]

print(np.sum(np.abs(diff - median)))


Measured memory_bytes: 49584
#include <bits/stdc++.h>
 
#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif
 
using namespace std;

vector<pair<int,int>> A, B;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int T1[3], T2[3];
	long long N, N2=0;
	cin>>N;
	for(int i=0;i<3;i++) cin>>T1[i];
	for(int i=0;i<3;i++) {
		cin>>T2[i];
		if(T1[i]<T2[i]) A.emplace_back(T1[i],T2[i]);
		else if(T1[i]>T2[i]) B.emplace_back(T2[i],T1[i]);
	}
	switch(A.size()) {
		case 0: N2=N; break;
		case 1:
			N2=N%A[0].first+N/A[0].first*A[0].second;
			break;
		case 2:
			for(int i=0;i<=N;i+=A[0].first) N2=max(N2,i/A[0].first*A[0].second+(N-i)%A[1].first+(N-i)/A[1].first*A[1].second);
			break;
		case 3:
			for(int i=0;i<=N;i+=A[0].first) for(int j=0;i+j<=N;j+=A[1].first) {
				N2=max(N2,i/A[0].first*A[0].second+j/A[1].first*A[1].second+(N-i-j)%A[2].first+(N-i-j)/A[2].first*A[2].second);
			}
			break;
	}
	switch(B.size()) {
		case 0: N=N2; break;
		case 1:
			N=N2%B[0].first+N2/B[0].first*B[0].second;
			break;
		case 2:
			for(int i=0;i<=N2;i+=B[0].first) N=max(N,1LL*i/B[0].first*B[0].second+(N2-i)%B[1].first+(N2-i)/B[1].first*B[1].second);
			break;
		case 3:
			for(int i=0;i<=N2;i+=B[0].first) for(int j=0;i+j<=N2;j+=B[1].first) {
				N=max(N,1LL*i/B[0].first*B[0].second+1LL*j/B[1].first*B[1].second+(N2-i-j)%B[2].first+(N2-i-j)/B[2].first*B[2].second);
			}
			break;
	}
	cout<<N<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;

int main(){
  int n,a;
  scanf("%d",&n);
  vector<pair<int,int>> v;
 rep(i,n){
    scanf("%d",&a);
    v.push_back(make_pair(a,i+1));
  }
  
  sort(all(v));
  for(auto x:v){
    a = x.second;
    printf("%d\n",a);
  }
}

Measured memory_bytes: 1780
n = gets.to_i
aa = []
memo = Array.new(41) {Array.new(21) {Array.new(10, 0)}}

n.times do
    a = gets.to_r
    s = a.denominator
    r = a.numerator

    x = (s & -s).bit_length - 1
    y = 0
    (y += 1; s /= 5) while s % 5 == 0
    z = [x, y].max

    if x > y
        y = x - y
        x = 0
    elsif x == y
        x = y = 0
    else
        x = y - x
        y = 0
    end

    x += (r & -r).bit_length - 1
    (y += 1; r /= 5) while r % 5 == 0
    
    memo[x][y][z] += 1
    aa << [x,y,z]
end

10.times do |k|
    40.times do |i|
        i = 39 - i
        20.times do |j|
            j = 19 - j
            memo[i][j][k] += memo[i+1][j][k] + memo[i][j+1][k] - memo[i+1][j+1][k]
        end
    end
end

ans = 0
aa.each do |x,y,z|
    10.times do |k|
        i = [k + z - x, 0].max
        j = [k + z - y, 0].max
        ans += memo[i][j][k]
    end
end

p (ans - memo[0][0][0]) / 2

Measured memory_bytes: 27428
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long A){
    if(N%500 <= A){
        cout << YES << endl;
    } else {
        cout << NO << endl;

    }
}

int main(){

    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    solve(N, A);
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
typedef long long ll;
#define  fi0(i,n)  for(size_t i=0;i<n;i++)
#define  vi         vector<int>
#define   vl        vector<ll>
#define   pb()    push_back()
#define   mk()    make_pair()
#define   fst      first
#define   scnd    second
#define   fast    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define   endl     '\n';
using namespace std;
void mum(){

}
void f(){

 }
void ff(){

}
int I[2][2]={1,0,0,1};
int a[1][2]={0,1};
int b[2][2]={0,1,1,1};
ll fun(int a[][2],int b[][2])
{
    for(int i=0;i<1;i++){
        for(int j=0;j<2;j++){
            for(int k=0;k<2;k++){

            }
        }
    }
}
void fff(){
     ll n,k;cin>>n>>k;
        ll a[n];
        fi0(i,n)cin>>a[i];
       for(int i=0;i<n;i++){
            for(int j=0;j<n-1;j++){
                if(a[j]<a[j+1]){
                    swap(a[j],a[j+1]);
                    k--;
                }
                if(k==0)break;
            }
            if(k==0)break;
       }
       fi0(i,n)cout<<a[i];
       cout<<endl;
}
int main()
{
    fast;
    int n;cin>>n;
    vl a(n+1),b(n);
    fi0(i,n+1)cin>>a[i];
    fi0(i,n)cin>>b[i];
    ll sum=0;
    for(int i=0;i<n;i++){
        if(a[i]<=b[i]){
            b[i]-=a[i];
            sum+=a[i];
            a[i]=0;
        }
        else {
            sum+=b[i];
            b[i]=0;
        }
        if(b[i]){
             if(a[i+1]<=b[i]){
            b[i]-=a[i+1];
            sum+=a[i+1];
            a[i+1]=0;
        }
        else {
            sum+=b[i];
        a[i+1]-=b[i];
            b[i]=0;
        }
    }
}
cout<<sum<<endl;
}



Measured memory_bytes: 4760
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int a,b,c,d,e,k;
    cin >>a>>b>>c>>d>>e>>k;
    int max_num,min_num;
    max_num = max(a,max(b,max(c,max(d,e))));
    min_num = min(a,min(b,min(c,min(d,e))));
    string ans = "Yay!";
    if(max_num - min_num > k){
        ans = ":(";
    }
    cout << ans << endl;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int dp[101][4][4][4];
//A 0 G 1 C 2 T 3
int main()
{
    int n;
    cin >> n;
    dp[0][3][3][3] = 1;
    for (int i = 0; i < n; i++)
    {
        //最後から１文字目
        for (int j = 0; j < 4; j++)
        {
            //最後から2文字目
            for (int k = 0; k < 4; k++)
            {
                //最後から3文字目
                for (int l = 0; l < 4; l++)
                {
                    if (dp[i][j][k][l] == 0)
                        continue;
                    for (int a = 0; a < 4; a++)
                    {
                        //AGC
                        if (a == 2 && j == 1 && k == 0)
                            continue;
                        //GAC
                        if (a == 2 && j == 0 && k == 1)
                            continue;
                        //ACG
                        if (a == 1 && j == 2 && k == 0)
                            continue;
                        //A?GC
                        if (a == 2 && j == 1 && l == 0)
                            continue;
                        //AG?C
                        if (a == 2 && k == 1 && l == 0)
                            continue;
                        dp[i + 1][a][j][k] += dp[i][j][k][l];
                        dp[i + 1][a][j][k] %= MOD;
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int k = 0; k < 4; k++)
            {
                ans += dp[n][i][j][k];
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long mark[100001],h[100001],res=0,m,n;

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

    cin>>n>>m;
    for (int i=1;i<=n;i++) cin>>h[i];
    for (int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        if (h[u]<=h[v]) mark[u]=1;
        if (h[v]<=h[u]) mark[v]=1;
    }
    for (int i=1;i<=n;i++)
    if (!mark[i]) res++;
    cout<<res;
}

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

//ループ関連
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

//定数
#define PI 3.14159265359
#define MOD 1000000007
#define INF 1000000000000

 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
  ll N, M, A;
  ll ans = 0;
  cin >> N >> M;
  REP(i, M) {
    cin >> A;
    ans += A;
  }
  N -= ans;
  if (N < 0)   cout << "-1";
  else cout << N;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <string.h>
using namespace std;
int main()
{
    long long n, m;
    cin >> n >> m;
    long long ans;
    if (2 * n < m)
        ans = n + (m - 2 * n) / 4;
    else
        ans = m / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF 2000000000

typedef long long ll;

int main(){
    char s[101];
    cin >> s;
    int len = strlen(s);
    bool flag[2] = {};
    REP1(i,len){
        if (flag[0]) {
            if (s[i] == 'F') {
                flag[1] = 1;
                break;
            }
        }else{
            if (s[i] == 'C') {
                flag[0] = 1;
            }
        }
    }
    if (flag[1]) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <vector>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int max_i = max(a, max(b, c));
	if ((max_i * 3 - a - b - c) % 2 == 0) {
		cout << (max_i * 3 - a - b - c) / 2 << endl;
	}
	else {
		cout << ((max_i + 1) * 3 - a - b - c) / 2 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < 9; ++i) {
		if (i * 111 < N && (i + 1) * 111 >= N) {
			cout << (i + 1) * 111 << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define SIZE 100
#define PROB 30

typedef struct data{
  int no;
  int ca;
  int rank;
} data_t;

data_t team[SIZE];

int main(int argc, const char *argv[])
{
  int i, j, k, v, p, max, tmp, rank = 1;
  while(scanf("%d,%d", &k, &v) == 2){
    if(!k && !v) break;
    team[k].no = k;
    team[k].ca += v;
  } 

  /* sort */
  for(i=0; i<SIZE; i++){
    max = i;
    for(j=i+1; j<SIZE; j++){
      if(team[max].ca < team[j].ca) max = j; 
    }
    tmp = team[i].ca;
    team[i].ca = team[max].ca;
    team[max].ca = tmp; 

    tmp = team[i].no;
    team[i].no = team[max].no;
    team[max].no = tmp;
  }

  /* rank */
  team[0].rank = rank;
  for(i=1; i<SIZE; i++){
    if(team[i-1].ca == team[i].ca){
      team[i].rank = rank;
    } else {
      rank++;
      team[i].rank = rank;
    }
  }

  /* display */
  while(scanf("%d", &p) == 1){
    for(i=0; team[i].no != p; i++);
    printf("%d\n", team[i].rank);
  }

  return 0;
}

Measured memory_bytes: 600
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

void Matrix(int *p, int length){
	int i, j, k, l, q;
	int **m;
	m = (int **)malloc(sizeof(int)*length);
	for (i = 0; i < length; i++)m[i] = (int *)malloc(sizeof(int)*length);

	for (i = 1; i < length; i++) m[i][i] = 0;

	for (l = 2; l < length; l++){
		for (i = 1; i < length - l + 1; i++){
			j = i + l - 1;
			m[i][j] = INT_MAX;
			for (k = i; k <= j - 1; k++){
				q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
				m[i][j] = (m[i][j] < q ? m[i][j] : q);
			}
		}
	}
	printf("%d\n", m[i][j]);
	//for (i = 0; i < length-1; i++)free(m[i]);
	//free(m);
}

main(){
	int i, n, *A;

	scanf("%d", &n);

	A = (int *)malloc(sizeof(int)*(n + 2));

	for (i = 1; i < n; i++) scanf("%d%d", &A[i], &A[i + 1]);
	scanf("%d%d", &A[i], &A[i + 1]);

	Matrix(A, n + 2);

	return 0;
}

Measured memory_bytes: 636
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    def check(m):
        for bf, c, af, ss in zip(m, m[1:], m[2:], s):
            if ss == 'o':
                if (c == 'S' and bf != af) or (c == 'W' and bf == af):
                    return False
            else:
                if (c == 'S' and bf == af) or (c == 'W' and bf != af):
                    return False
        return True

    n = int(readline())
    s = readline().rstrip().decode()
    flag = {'S': 'W', 'W': 'S'}
    for m in ('SS', 'SW', 'WS', 'WW'):
        for i, ss in enumerate(s[1:-1]):
            if ss == 'o':
                if m[i + 1] == 'S':
                    m += m[i]
                else:
                    m += flag[m[i]]
            else:
                if m[i + 1] == 'S':
                    m += flag[m[i]]
                else:
                    m += m[i]
        if check(m[-1] + m + m[0]):
            print(m)
            break
    else:
        print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9500
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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 <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if (x / d >= k)
        cout << abs(x - k * d) << endl;
    else {
        k -= x / d;
        x = x - x / d * d;
        if (k % 2 == 1)
            cout << abs(d - x) << endl;
        else
            cout << x << endl;
    }
}

Measured memory_bytes: 3604
n, t = gets.chomp.split(' ').map(&:to_i)
strs = n.times.map{ gets.chomp.split(' ').map(&:to_i) }
ok_path = strs.select{ |str| str[1] <= t }
if ok_path.empty?
  puts 'TLE'
else
  puts ok_path.min_by{ |str| str[0] }[0]
end


Measured memory_bytes: 3836
#include <iostream>
#include <cstdio>                              //scanf,printf
#include <algorithm>                           //max,min
#include <string>                              //string
#include <cstring>                             //strlen,strcat
#include <cctype>                              //isalpha,tolower
using namespace std;

string toUpper(string s){
    string t=s;
    for(int i=0; i<s.size(); i++){
        t[i]=toupper(t[i]);
    }
    return t;
}

int main(){
    string target,text;
    int sum=0;
    cin>>target;
    for(int i=0; i<target.size(); i++){
        target[i]=toupper(target[i]);
    }
    while(1){
        cin>>text;
        if(text=="END_OF_TEXT") break;
        text = toUpper(text);
        if(text==target) sum++;
    }
    cout<<sum<<endl;
}



Measured memory_bytes: 3228
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>

using namespace std;

int Algae(int r, int D, int x)
{
    return x * r - D;
}

int main()
{
    int r, D, x2000;
    cin >> r >> D >> x2000;

    for (int i = 0; i < 10; i++)
    {
        int X;

        if (i == 0)
        {
            X = Algae(r, D, x2000);
        }
        else
        {
            X = Algae(r, D, X);
        }
        cout << X << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
long long int __lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
 //__gcd 最大公約数
 //__lcm 最小公倍数
 //double 少数（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
 
int main() {
  int a;
  cin>>a;
  vector<int> b(a),c(a+1);
  for(int i=0;i<a+1;i++)
    cin>>b[i];
  for(int i=0;i<a;i++)
    cin>>c[i];
  long long int d=0;
  for(int i=0;i<a;i++){
    if(b[i]>=c[i])
      d+=c[i];
    else if(b[i]+b[i+1]>c[i]){
      d+=c[i];
      b[i+1]+=b[i]-c[i];
    }
    else{
      d+=b[i]+b[i+1];
      b[i+1]=0;
    }
  }
  cout<<d;
}

Measured memory_bytes: 1024